python 中作为列表的命令行参数

Command line arguments as a list in python

例如:

python3 test.py Tejas ALL
or
python3 test.py Tejas EAM EAB EAC

参数应存储为列表变量,如:

cli_arg = ['Tejas', 'ALL']
or 
cli_arg = ['Tejas', 'EAM', 'EAB', 'EAC']
import sys

argsList = [arg for index, arg in enumerate(sys.argv) if index != 0]

print(argsList)   // Output - ['Tejas', 'EAM', 'EAB', 'EAC']

正如@Tomerikoo 所指出的——下面的代码要简单得多

argList = sys.argv[1:]