开发者

Python: Printing Unicode to File

开发者 https://www.devze.com 2023-01-05 00:26 出处:网络
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 filesomefile = codecs.open(\
   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

精彩评论

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