Python Intro - Parse Command Line Parameters
2015-04-10 16:43
465 查看
#!/usr/local/bin/python3
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)
print("opts = ", opts)
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("inputfile = ", inputfile)
print("outputfile = ", outputfile)
if __name__ == "__main__":
main(sys.argv[1:])
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)
print("opts = ", opts)
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("inputfile = ", inputfile)
print("outputfile = ", outputfile)
if __name__ == "__main__":
main(sys.argv[1:])
相关文章推荐
- How to parse command line parameters.
- InfoPath: Passing Command Line parameters to a new form
- 微软的两个非常实用的C++类(Timer与ParseCommandLine)
- python 命令行使用(command line options usage)
- ParseCommandLine
- Read Unicode characters from command-line arguments in Python 2.x on Windows
- InfoPath: Passing Command Line parameters to a new form
- Python Shell(command line模式和GUI模式)区别
- C argc and argv Examples to Parse Command Line Arguments
- Python - Parser for command line options - argparse
- python,sql,sqlite3,django,db,command line
- [RT] Twitter from the command line in python using OAuth
- wince -- Automatically Start Application with Command Line Parameters
- freemarker.core.InvalidReferenceException: Expression parameters.parseContent is undefined on line 45, column 28 in template/aja
- grub 内核启动参数(kernel command-line parameters)
- <ZT>ParseCommandLine 有关命令行启动参数的一些技巧
- freemarker.core.InvalidReferenceException: Expression parameters.parseContent is undefined on line 45, column 28 in template/aja
- 如何在Windows下开发Python:在cmd下运行Python脚本+如何使用Python Shell(command line模式和GUI模式)+如何使用Python IDE
- C argc and argv Examples to Parse Command Line Arguments