Debian Linux Squeeze 如何安装Python v2.6/2.5 Argparse模块
时间:2019-11-20 08:53:08 来源:igfitidea点击:
在Debian Linux Squeeze 6.0中如何安装Python模块argparse?
Argparse是一个命令行解析库。添加了位置参数和可选参数,使用更方便灵活。
安装argparse模块
执行以下命令:
$ sudo apt-get install python-argparse
argparse模块使用示例
解析 Python命令行参数示例
<pre lang="python">
#!/usr/bin/python
import argparse
__author__ = 'theitroad'
parser = argparse.ArgumentParser(description='This is a demo script by theitroad.')
parser.add_argument('-i','--input', help='Input file name',required=True)
parser.add_argument('-o','--output',help='Output file name', required=True)
args = parser.parse_args()
## show values ##
print ("Input file: %s" % args.input )
print ("Output file: %s" % args.output )

