【发布时间】:2014-12-16 16:31:50
【问题描述】:
我想取消转义源文件中的 unicode 字符:
source = open('source.csv', 'r')
target = open('target.csv', 'w')
target.write(source.read().decode('unicode_escape').encode('utf-8'))
但结果文件包含额外的换行符。例如,文本
u'\u0417a\u0439\u043c\u044b \u0412ce\u043c \u0436e\u043ba\u044e\u0449\u0438\u043c!\nO\u0434o\u0431\u0440e\u043d\u0438e 98%'
被替换为
u'Зaймы Вceм жeлaющим!
Oдoбрeниe 98%'
了解源文本中有换行符\n,但我想保持原样,无需实际转换为换行符。
【问题讨论】:
标签: python file python-2.7 line-breaks