python参数之间用什么分隔
python参数之间用什么分隔?
python之分割参数getopt
import sys
import getopt
def usage():
print("Usage:%s [-a|-o|-c] [--help|--output] args...." %Dsys.argv[0]);
if "__main__" == __name__:
#lsArgs = [""];
try:
opts,args = getopt.getopt(sys.argv[1:], "ao:c", ["help", "output="]);
print("============ opts ==================");
print(opts);
print("============ args ==================");
print(args);
#check all param
for opt,arg in opts:
if opt in ("-h", "--help"):
usage();
sys.exit(1);
elif opt in ("-t", "--test"):
print("for test option");
else:
print("%s ==> %s" %(opt, arg));
except getopt.GetoptError:
print("getopt error!");
usage();
sys.exit(1);
运行结果:
$ ./test_getopt.py -a -oaaa -caa --output=out file1 t file2 -d
============ opts ==================
[('-a', ''), ('-o', 'aaa'), ('-c', ''), ('-a', ''), ('-a', ''), ('--output', 'out')]
============ args ==================
['file1', 't', 'file2', '-d']
-a ==>
-o ==> aaa
-c ==>
-a ==>
-a ==>
--output ==> out
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: python参数之间用什么分隔
本文地址: https://pptw.com/jishu/61592.html
