python getopt 参数处理小示例

yipeiwu_com5年前Python基础
opts, args = getopt.getopt(sys.argv[1:], "t:s:h", ["walletype=", "servicename=",'help'])
for a,o in opts:
if a in ('-t', '--walletype'):
walle_type = o
elif a in ('-s', '--servicename'):
service_name = o
elif a in ('-h', '--help'):
help = True

其中t:s:h表示参数的缩写,:表示参数后需要传值

walletype=,servicename=,help表示参数的全称,=表示后面需要传值

相关文章

django 捕获异常和日志系统过程详解

这一块的内容很少, 异常使用try except即可, 日志只需要几行配置. 使用装饰器捕获方法内的所有异常 我使用装饰器来整个包裹一个方法, 捕获方法中的所有异常信息.并将其转为j...

Python 将pdf转成图片的方法

Python 将pdf转成图片的方法

本篇文章记录如何使用python将pdf文件切分成一张一张图片,包括环境配置、版本兼容问题。 环境配置(mac) 安装ImageMagick brew install imagemagi...

Python使用bs4获取58同城城市分类的方法

本文实例讲述了Python使用bs4获取58同城城市分类的方法。分享给大家供大家参考。具体如下: # -*- coding:utf-8 -*- #! /usr/bin/python...

python利用datetime模块计算时间差

今天写了点东西,要计算时间差,我记得去年写过,于是今天再次mark一下,以免自己忘记 In [27]: from datetime import datetime In [28]:...

python清除字符串前后空格函数的方法

python有时候需要清除字符串前后空格,而字符本身的空格不需要清除掉,那就不能用正则re.sub来实现。 这时用到strip()函数 用法: str = ' 2014-04-21...