我在剪贴板上有一些utf-8文本和一个没有任何内容的utf-8 .txt文件。
如果我在notepad++中打开文件,并使用ctrl+v粘贴,我得到的是utf-8格式,其中没有那些?
但是如果我使用python代码从剪贴板中获取文本,并在追加模式下打开文件并将其写入其中,那么在notepad++中查看该文件时,我会看到其中的?
是否有一些特殊的python代码可以从剪贴板中获取文本并将其写入到一个空的utf-8文件中,这样,如果我在notepad++中之后查看该文件,我将看不到这些?
有人知道吗?
发布于 2012-04-14 12:11:21
使用codecs模块:
import codecs
file = "/path/to/save/file.txt"
# instead of open(file,'w') do:
f = codecs.open(file, encoding='utf-8',mode='w+')
# Write a unicode string to the file.
f.write(u'\u4500 blah blah blah\n')https://stackoverflow.com/questions/10150349
复制相似问题