使用python argparser处理命令行参数

 #coding:utf-8
# 导入模块
import argparse # 创建ArgumentParser()对象
parser = argparse.ArgumentParser() # 调用add_argument()方法添加参数
#添加定位参数
parser.add_argument("square", help="display a square of a given number", type=int)
#添加可选参数
parser.add_argument("--square", help="display a square of a given number", type=int)
parser.add_argument("--cubic", help="display a cubic of a given number", type=int) # 使用parse_args()解析添加的参数
args = parser.parse_args() print args.square
print args.cubic

python_argparse的更多相关文章

  1. python的os模块fnmatch模块介绍

    一.先介绍一下os模块 import os print(os.getcwd()) # E:\python\test\python_models # 获取当前的目录 print(os.listdir(& ...

随机推荐

  1. ubuntun16.04不支持intel的最新网卡,升级到17.10后解决

    新买的神舟战神电脑.装了ubuntu16.04版本.但是安装后无线网卡无法使用无线网卡型号:是intel的一款网卡02:00.0 Network controller [0280]: Intel Co ...

  2. !推荐:下载abap 源代码

    转自http://blog.sina.com.cn/s/blog_4d1570de0100pvhd.html *@------------------------------------------- ...

  3. appium(4)-Automating mobile web apps

    Automating mobile web apps If you’re interested in automating your web app in Mobile Safari on iOS o ...

  4. Centos7利用kvm搭建Windows虚拟机

    这几天玩了一下kvm虚拟化,真的很有意思,我把这几天踩的坑,还有收获,都记录下来,作为以后的复习和检查. 首先说一下我的基本逻辑,我有一台win7的笔记本,我的底层虚拟化是使用VMWare构建的Cen ...

  5. govendor

    cd  到工程目录. govendor init : 初始化 govendor fetch : 拉取包 go 1.6以后编译go代码会优先从vendor目录先寻找依赖包: controllers\ar ...

  6. 【bzoj2588】Count on a tree 主席树

    这题给人开了个新思路. 原本构造一个序列的主席树,是这个位置用上个位置的信息来省空间,树上的主席树是继承父亲的信息来省空间. 此题若带修改怎么办? 若对某个点的权值做修改,则这个点的子树都会受影响,想 ...

  7. LightOJ1220 —— 质因数分解

    题目链接:https://vjudge.net/problem/LightOJ-1220 1220 - Mysterious Bacteria    PDF (English) Statistics ...

  8. BZOJ 2023 [Usaco2005 Nov]Ant Counting 数蚂蚁:dp【前缀和优化】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2023 题意: 有n个家族,共m只蚂蚁(n <= 1000, m <= 1000 ...

  9. TCP连接过程

    TCP建立连接与释放连接  最近复习准备<计算机网络>考试,感觉TCP协议建立连接与释放连接这两个过程比较重要,所以把自己理解的部分写下来. 1.建立连接:(三次握手)   (1)客户端发 ...

  10. 兼容html5新标签及媒体查询引入插件

    <!-- 以下2个插件是用于在IE8支持HTML5元素和媒体查询的,如果不用可移除 --> <!--[if lt IE 9]> <script src="htt ...