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
原文地址:https://www.cnblogs.com/chenxi188/p/11363486.html