赞
踩
import csv
import os
# 打开 CSV 文件
with open('转换后-测试.csv', 'w',newline='', encoding='utf-8') as f_w:
f_w = csv.writer(f_w)
with open('测试.csv', newline='', encoding='ansi') as csvfile:
# 读取 CSV 文件内容
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
# 遍历 CSV 文件中的每一行数据
for row in reader:
# 处理每一行数据
# print(row)
f_w.writerow(row)
# -*- coding: UTF-8 -*- ''' @Project :xxx @File :转utf8.py @IDE :PyCharm @Author :一晌小贪欢 @Date :2023/10/13 10:29 ''' import csv import os # 打开 CSV 文件 for f in os.listdir("./utf8待转/"): with open('./utf8保存/utf8-'+f, 'w',newline='', encoding='utf-8') as f_w: f_w = csv.writer(f_w) with open("./utf8待转/"+f, newline='', encoding='ansi') as csvfile: # 读取 CSV 文件内容 reader = csv.reader(csvfile, delimiter=',', quotechar='"') # 遍历 CSV 文件中的每一行数据 for row in reader: # 处理每一行数据 # print(row) f_w.writerow(row) print(f,"转换成功!!!")
import csv import os # 打开 CSV 文件 for f in os.listdir("./utf8待转/"): with open('./utf8保存/'+f, 'w',newline='', encoding='utf-8') as f_w: f_w = csv.writer(f_w) try: with open("./utf8待转/"+f, newline='', encoding='ansi') as csvfile: # 读取 CSV 文件内容 reader = csv.reader(csvfile, delimiter=',', quotechar='"') # 遍历 CSV 文件中的每一行数据 for row in reader: # 处理每一行数据 # print(row) f_w.writerow(row) except: with open("./utf8待转/" + f, newline='', encoding='utf-8') as csvfile: # 读取 CSV 文件内容 reader = csv.reader(csvfile, delimiter=',', quotechar='"') # 遍历 CSV 文件中的每一行数据 for row in reader: # 处理每一行数据 # print(row) f_w.writerow(row) print(f,"转换成功!!!")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。