1. argparse
import argparse
def test():
parser = argparse.ArgumentParser(description="test")
parser.add_argument('-n','--name',default="alex")
parser.add_argument('-y', '--year',default="18")
parser.add_argument('-c','--city',default='beijing')
args = parser.parse_args()
name = args.name
year = args.year
city = args.city
print(f'my name is {name}, {year} years old. my city is {city}')
if __name__ == '__main__':
test()
执行命令时:
python test.py -y 23 -c shanghai -n tony
2. fire
import fire
def hello(name):
return 'Hello {name}!'.format(name=name)
if __name__ == '__main__':
fire.Fire(hello)
调用
python test.py test
3. sys
在右键菜单中调用python脚本.
import sys
script,first,second,third = sys.argv
print ("The script is called:{%s}"% script)
print ("The first variable is:{%s}"% first)
print ("The second variable is:{%s}"% second)
print ("The third variable is:{%s}"% third)
4. 右键

5. 注册表

注意参数的设置

