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))+'\n')

运行:

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

python script_name.py 参数1 参数2

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-14
  • 2021-12-25
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
相关资源
相似解决方案