我在Python中有一個使用函數的問題。這是我的主要功能的一部分:使用函數不能與getopt一起使用
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
或./code.py -h
(它是可執行的),我得到了什麼,但Python的幫助。
你是什麼意思的「除python幫助之外的任何東西」?每種情況下的輸出究竟是什麼?你的代碼看起來是正確的。 – agf
'用法:python [選項] ... [-c cmd | -m mod |文件| - ] [arg] ...' – Alejandro
您將需要向我們展示更多代碼。我沒有看到什麼觸發了你粘貼的Python使用線。 – agf