码迷,mamicode.com
首页 > 编程语言 > 详细

Python Simple Unicode Instance

时间:2015-12-02 22:21:32      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

#!/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

Python Simple Unicode Instance

标签:

原文地址:http://www.cnblogs.com/magicpower/p/5014130.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!