我对 Python 中的使用函数有疑问。这是我的主要功能的一部分:
def main(argv):
try:
opts, args = getopt.getopt(argv, 'hi:o:tbpms:', ['help', 'input=', 'output='])
if not opts:
print 'No options supplied'
usage()
except getopt.GetoptError,e:
print e
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ('-h', '--help'):
usage()
sys.exit(2)
if __name__ =='__main__':
main(sys.argv[1:])
我也定义了一个使用函数
def usage():
print "\nThis is the usage function\n"
print 'Usage: '+sys.argv[0]+' -i <file1> [option]'
但是当我以./code.py
or ./code.py -h
(它是可执行的)运行我的代码时,我得到了除了 Python 帮助之外的任何东西。