1.argv详解
#argv的含义是把argv中的东西解包,
#将所有的参数依次赋值给左边的这些变量。#在CMD或者powershell里面运行该代码文件,格式如下:
#python py文件名 参数1 参数2 参数3 ...
#下面这个实例命令是:
#python c:\Users\Administartor\Desktop\python_something\argv.py 1 2 3
# 其中c:\Users\Administartor\Desktop\python_something\argv.py 这个文件地址代表script
# 后面跟的1 2 3分别代表 one, two, third的值
# 下面代码中的script, one, two, third = argv 与上面的内容相呼应。
from sys import argv
script, one, two, third = argv #该代码和命令行的参数相呼应
print("The script is called:",script)
print("Your first variable is:",one)
print("Your second variable is:",two)
print("Your third variable is:",third)
#实际工作中,在最后要执行close()代码,关闭打开的文档。
#命令行里的参数1,2,3可以任意写,代码中的on