我开始一致输都是错的, 运行老是报错, 就是没想明白。
cmd 中运行的
python 1csv_simple_parsing_and_write.py supplier_data.csv out/1out2.csv
1 这是需要运行的语句
python 1csv_simple_parsing_and_write.py
2 需要运行的内容supplier_data.csv
3 out (输出的文件夹名称)
4 输出的文件名称。
就是这个文件夹名称一直错误,因为我没有新建。
#!/usr/bin/env python3 import sys input_file = sys.argv[1] output_file = sys.argv[2] with open(input_file, 'r', newline='') as filereader: with open(output_file, 'w', newline='') as filewriter: header = filereader.readline() header = header.strip() header_list = header.split(',') print(header_list) filewriter.write(','.join(map(str,header_list))+' ') for row in filereader: row = row.strip() row_list = row.split(',') print(row_list) filewriter.write(','.join(map(str,row_list))+' ')