import csv
with open('c:/python34/test.csv', 'a', encoding='cp949') as csvfile:
fieldnames = ['num']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames, delimiter=',', lineterminator='\n',)
writer.writeheader()
writer.writerow({'num': '04'})
打开test.csv文件时结果
4
我想在csv文件中写 04
,但是当我打开test.csv文件时,它是 4
帮助我
答案 0 :(得分:0)
尝试添加额外的'在04之前允许它不被剥离excel:
import csv
with open('c:/python34/test.csv', 'a', encoding='cp949') as csvfile:
fieldnames = ['num']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames, delimiter=',', lineterminator='\n',)
writer.writeheader()
writer.writerow({'num': '\'04'}) #changed to escaped '