当前位置 : 主页 > 编程语言 > python >

Python的sys.argv用法

来源:互联网 收集:自由互联 发布时间:2021-06-25
import sysa = sys.argv[:]print("输入的参数为:", a)def train_start(start_time, end_time, select_equipment): print('start_time = ', start_time) print("end_time = ", end_time) print('select_time = ', select_equipment) ids = select_equi
import sys
a = sys.argv[:]
print("输入的参数为:", a)

def train_start(start_time, end_time, select_equipment):
    print('start_time = ', start_time)
    print("end_time = ", end_time)
    print('select_time = ', select_equipment)
    ids = select_equipment.split(',')
    print("ids = ", ids)


if __name__ == "__main__":
    for i, argv in enumerate(sys.argv[:]):
        print("i = ", i, '; argv = ', argv)
    print("=========================")
    if len(sys.argv) == 5 and sys.argv[4] == '0':
        start_time = sys.argv[1]
        end_time = sys.argv[2]
        select_equipment = sys.argv[3]
        train_start(start_time, end_time, select_equipment)


# 命令行输入:python test.py 2019-08-05 2019-09-01 1,5 0

网友评论