python参数传递_Python 参数传递

该博客介绍了如何在Python中使用getopt模块解析命令行参数。通过示例展示了如何处理输入文件、输出文件、时间间隔等参数,并提供了帮助文档。在遇到错误时,程序会打印错误信息并退出。
摘要由CSDN通过智能技术生成

#!-*-coding:utf8 -*-

#要在首行才可以在后面用中文注释

import getopt

import sys

import os

if __name__ == '__main__':

# ...

helpdoc = '''

Description

...

Usage

python pyscript.py -i/--ifile -o/--ofile -t/--time ...

Parameters

-h/--help

Print helpdoc

-i/--ifile

Input file,including only one column with sampleId

-o/--ofile

Output file, including two columns, the 1st column is sampleId, the 2nd column is attribute information

-t/--time

Time for interval (seconds, default 5s)

...

'''

try:

opts,args = getopt.getopt(sys.argv[1:], "hi:o:t:n:", ["help","ifile=", "ofile=", "time="])

if len(opts) == 0:

print("Options Error!\n\n"+helpdoc)

sys.exit(2)

except getopt.GetoptError:

print("Options two Error!\n\n"+helpdoc)

sys.exit(2)

for opt,arg in opts:

if opt in ("-h","--help"):

print(helpdoc)

sys.exit()

elif opt in ("-i","--ifile"):

infile = arg

elif opt in ("-o","--ofile"):

outfile = arg

elif opt in ("-t","--time"):

sleep_time = int(float(arg))

elif opt in ("-n","--requests-number"):

requestNum = int(float(arg))

print (infile)

print (outfile)

print (sleep_time)

print (requestNum)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值