读取逗号分隔txt文件且对某列数据进行提取
import os #读取文件数据 print(os.path.dirname(__file__)) with open('./test.txt', 'r',encoding='UTF-8') as file: content = file.readlines() file.close()
对于数据进行处理 for line in content: data=line.strip().split(',') print(data[6]) #逐行写入文件 with open ('./test1.txt','a',encoding='UTF-8') as file: file.write(data[6]) file.write('\n') file.close()