Python的sys.argv用法

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

posted on 2019-10-22 09:59  星辰之衍  阅读(99)  评论(0编辑  收藏

导航