【发布时间】:2013-08-18 00:00:34
【问题描述】:
这是我的程序(test.py):
#!/usr/bin/python
import sys, getopt
def main(argv):
inputfile = ''
outputfile = ''
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
except getopt.GetoptError:
print 'test.py -i <inputfile> -o <outputfile>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'test.py -i <inputfile> -o <outputfile>'
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
print 'Input file is "', inputfile
print 'Output file is "', outputfile
if __name__ == "__main__":
main(sys.argv[1:])
使用 msdos 命令行我可以像这样传递 -h 选项(在 test.py 中定义):
python test.py -h
然后 msdos 命令行会输出:
test.py -i <inputfile> -o <outputfile>
但是我如何在 python 交互中传递 -h 选项 使用 msdos 命令行完成的模式?
【问题讨论】:
标签: python