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,
Hello world
utf8写文件
原创xiangjie256 博主文章分类:Python ©著作权
©著作权归作者所有:来自51CTO博客作者xiangjie256的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:python排序
下一篇:ubuntu sudo不输密码
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
python utf8读写文件
import codecsf = codecs.open(file_name, "w", "utf-8")
职场 休闲 python utf8 读写文件 -
python utf8写文件 python写入utf8
python写utf-8文件的问题
python utf8写文件 python utf 8 Mac ci 字符串 -
python 指定用 utf8 打开文件 python open utf8
open()方法Python open() 方法用于打开一个文件,并返回文件对象,在对文件进行处理过程都需要使用到这个函数,如果该文件无法被打开,会抛出 OSError。注意:使用 open() 方法一定要保证关闭文件对象,即调用 close() 方法。 open() 函数常用形式是接收两个参数:文件名(file)和模式(mode)。一般格式:open(file, mode='r')完整
c++读取utf8文件 file watchers怎么默认打开 file 关闭 file对象怎样获取文件的长度? file需要关闭吗