Python: Printing Unicode to File
file = open('unicode.txt', 'wb')
for i in range(10):
file.write(str(unichr(i) ))
What i would like to do 开发者_C百科is to print all of the Unicode values to a text file
somefile = codecs.open('unicode.txt', 'wb', someencoding)
for i in range(10):
somefile.write(unichr(i))
You shouldn't need the str()
call around unichr(i)
. Python unicode
objects are printable.
This:
file = open('unicode.txt', 'wb')
for i in range(10):
file.write(unichr(i))
Seems to work for me, it prints 0x0000, 0x0001, 0x0002, etc. to the text file.
精彩评论