import csv
import os
# csv存放路径(本地D盘路径下的文件夹)
path = 'D:\\csv';
# txt文件存放路径
txtPath = 'D:\\txt';
for file_name in os.listdir(path):
full_path = os.path.join(path, file_name)
# 获取文件名称(不含后缀)
name = file_name.split('.')[0]
# 拼接txt文件名
txt_Path = os.path.join(txtPath, name + '.txt')
a = open(full_path, 'r')
reader = csv.reader(a)
# 跳过第一行 不跳就注释掉
next(reader)
#遍历数据并写入到txt文件中
with open(txt_Path, 'w') as f:
for i in reader:
for x in i:
f.write(x)
f.write('\t')
f.write('\n')
a.close()
with open(txt_Path, 'r') as f:
print(f.read())