小知识点_python基础_默认参数调用_getopt

#https://www.cnblogs.com/zz22--/p/7719285.html
#https://www.jianshu.com/p/a877e5b46b2d

import getopt
import sys

opts,args = getopt.getopt(sys.argv[1:],'-h',['filename1=','filename2=','filename3=','filename4=','version',])

print(opts)
filename1=1
filename2=2
filename3=3
filename4=4

for opt_name,opt_value in opts:
    if opt_name in ('-h','--version'):
        print("指导说明")

    if opt_name in ('--filename1'):
        filename1 = opt_value


    if opt_name in ('--filename2'):
        filename2 = opt_value

    if opt_name in ('--filename3'):
        filename3 = opt_value


    if opt_name in ('--filename4'):
        filename4 = opt_value


print("filename1 is ",filename1)
print("filename2 is ",filename2)
print("filename3 is ",filename3)
print("filename4 is ",filename4)
print("shushushushusuhsushu ")

python3 test.py --filename3=9   --filename4=100

你可能感兴趣的:(python)