• argv从控制台输入多个参数


    arg多个参数:

    #!/usr/bin/env python3
    import sys
    
    #控制台要输入的两个参数格式为:python script_name.py 参数1 参数2
    input_file=sys.argv[1]
    output_file=sys.argv[2]
    
    #
    with open(input_file,'r',newline='')as file_read:
        with open(output_file,'w',newline='')as file_write:
            header=file_read.readline()
            header=header.strip()
            header_list=header.split(',')
            print(header_list)
            file_write.write(','.join(map(str,header_list))+'
    ')

    运行:

    在脚本文件夹里shift+右键——在此处打开命令窗口——输入:

    python script_name.py 参数1 参数2
  • 相关阅读:
    例7-13
    例7-11
    例7-1
    例6-5
    例6-3
    例6-2
    例6-1
    例5-9
    例5-8
    例5-7
  • 原文地址:https://www.cnblogs.com/chenxi188/p/11363486.html
Copyright © 2020-2023  润新知