开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜