import codecs
f = codecs.open(filename, 'r', 'cp1251')
u = f.read() # Now the contents have been transformed to a Unicode string
out = codecs.open(output, 'w', 'utf-8')
out.write(u) # and Now the contents have been output as UTF-8
这是您打算做什么?
Python:如何从Windows 1251转换为Unicode?
import codecs
f = codecs.open(filename, 'r', 'cp1251')
u = f.read() # Now the contents have been transformed to a Unicode string
out = codecs.open(output, 'w', 'utf-8')
out.write(u) # and Now the contents have been output as UTF-8
这是您打算做什么?