擅长:python、mysql、java
<p>你可以接住getopt.GetoptError并亲自检查“opt”和“msg”属性:</p>
<pre>
try:
opts, args = getopt.getopt(sys.argv[1:], "c:", ...
except getopt.GetoptError, e:
if e.opt == 'c' and 'requires argument' in e.msg:
print >>sys.stderr, 'ERROR: You forgot to give the file name after -c option'
sys.exit(-1)
</pre>