argparse是python的一个命令行参数模块,可以解析命令行参数,生成帮助.

示例:

#!/usr/bin/python

from argparse import ArgumentParser

argv = ArgumentParser(usage='it is usage tip', description='this is a test')
argv.add_argument('--string', default='strings', type=int, help='the first string argument')
argv.add_argument('--int', default=1, type=str, help='the second argument') args = argv.parse_args() #打印所有参数
print args #打印某一个参数
print args.string
print args.int

参数-h --help来显示帮助信息。

python获取参数的更多相关文章

  1. python获取参数列表

    def f(a=1, b=2, c=3): print(locals())#在函数内获取 #使用inspect模块,简单方便 python2.7: import inspectinspect.geta ...

  2. python命令行获取参数

    python命令行获取参数 import sys # python获取参数 input_file = sys.argv[1] output_file = sys.argv[2] print(input ...

  3. python DRF获取参数介绍

    DRF获取参数的方式 例如url url(r'^demo/(?P<word>.*)/$', DemoView.as_view()) 在类视图中获取参数 url:http://127.0.0 ...

  4. python获取输入参数

    python获取输入参数 学习了:https://www.cnblogs.com/angelatian/p/5832448.html import sys模块: len(sys.argv)参数个数 s ...

  5. python 获取日期

    转载   原文:python 获取日期 作者:m4774411wang python 获取日期我们需要用到time模块,比如time.strftime方法 time.strftime('%Y-%m-% ...

  6. [py]os.walk爬目录&sys.argv灵活获取参数

    1, 遍历目录 os.walk('/tmp') os.next()   2,sys.argv ######################################## py@lanny:~/t ...

  7. Python获取目录、文件的注意事项

    Python获取指定路径下的子目录和文件有两种方法: os.listdir(dir)和os.walk(dir),前者列出dir目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >> ...

  8. python函数参数的pack与unpack

    python函数参数的pack与unpack 上周在使用django做开发的时候用到了mixin(关于mixin我还要写一个博客专门讨论一下,现在请参见这里),其中又涉及到了一个关于函数参数打包(pa ...

  9. Python 获取时间戳

    Python 获取时间通过 time 模块 如下代码,是通过获取当前的时间,按照格式输出 Python默认获取当前的时间返回的都是时间的元组,下面是元组的,字符串时间的一个转换输出 # -*- cod ...

随机推荐

  1. Linux 脚本编写

    第一个shell脚本编写 #!/bin/bash # 上面中的 #! 是一种约定标记, 它可以告诉系统这个脚本需要什么样的解释器来执行; #定义变量: APP_BASE_PATH="/opt ...

  2. Cannot find name 'AsyncIterator' error in Typescript compilation process 问题解决

    解决方法: tsconfig.json: 添加lib 编译选项 { "compilerOptions": { "lib":[ "esnext.asyn ...

  3. winform 勾选可以改变框控件

    public partial class UCCheck : UserControl { [Browsable(true), Category("修改属性"), Descripti ...

  4. 安装 nodejs,npm,pm2

    一:需要安装组件: nodejs,npm,pm2 安装epel 源: rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel ...

  5. php代码编译的实现

    1.php是解析型的高级语言,zend内核使用c语言实现,有main函数,php脚本就是输入,内核处理后输出结果,内核将php脚本翻译成c程序可识别的opcode就是php的编译. c语言的编译将c代 ...

  6. 第十九课 golang中的下划线

    在 Golang 里, _ (下划线)是个特殊的标识符. 用在 import 在导包的时候,常见这个用法: 1 2 import _ "net/http/pprof" import ...

  7. C细节学习

    字符串ascii码值比较compress函数;

  8. python一些不错的东西

    1 cmd命令行写代码的加强版  ipython  直接用pip安装就可以   php install Ipython 2 不错的数据分析 机器语言的 Python(x,y)是一个基于python的科 ...

  9. leetcode205

    public class Solution { public bool IsIsomorphic(string s, string t) { if (s.Length != t.Length) { r ...

  10. 图像特征与描述子(直方图, 聚类, 边缘检测, 兴趣点/关键点, Harris角点, 斑点(Blob), SIFI, 纹理特征)

    1.直方图 用于计算图片特征,表达, 使得数据具有总结性, 颜色直方图对数据空间进行量化,好比10个bin 2. 聚类 类内对象的相关性高 类间对象的相关性差 常用算法:kmeans, EM算法, m ...