from pathlib import Path
import csv

source = Path('input.csv')
target = Path('output-utf8.csv')
if target.exists():
    raise FileExistsError('输出文件已经存在，请先检查或更换名称')
with source.open('r', encoding='gb18030', newline='') as src, target.open('x', encoding='utf-8-sig', newline='') as dst:
    reader = csv.reader(src)
    writer = csv.writer(dst)
    count = 0
    for row in reader:
        writer.writerow(row)
        count += 1
print('已写入记录数（含表头）:', count)
