__MagicPower
Do one thing and do it best!

导航

 
#!/usr/bin/env python
#--*-- coding:utf-8 --*--
'''
An example of reading and writing Unicode string :Writes a Unicode
string to a file in utf-8 and reads it back in.
'''
CODEC = 'utf-8'
FILE = 'unicode.txt'

hello_out = u"Hello world\n"
bytes_out = hello_out.encode(CODEC)
f = open(FILE,"w")
f.write(bytes_out)
f.close()

f = open(FILE,"r")
bytes_in = f.read()
f.close()
hello_in = bytes_in.decode(CODEC)
print hello_in

Write an string in form of Unicode to file named 'unicode.txt'

then read the contents and display on screen

posted on 2015-12-02 20:38  __MagicPower  阅读(166)  评论(0编辑  收藏  举报