1测试成功的Python中文文件读写脚本#coding=utf-8
 2测试成功的Python中文文件读写脚本import os
 3测试成功的Python中文文件读写脚本import codecs
 4测试成功的Python中文文件读写脚本
 5测试成功的Python中文文件读写脚本def writefile(fn, v_ls):
 6测试成功的Python中文文件读写脚本    f = codecs.open(fn, 'wb''utf-8')
 7测试成功的Python中文文件读写脚本    for i in v_ls:
 8测试成功的Python中文文件读写脚本        f.write(i + os.linesep)
 9测试成功的Python中文文件读写脚本    f.close()
10测试成功的Python中文文件读写脚本
11测试成功的Python中文文件读写脚本def readfile(fn):
12测试成功的Python中文文件读写脚本    f = codecs.open(fn,'r','utf-8')
13测试成功的Python中文文件读写脚本    ls = [ line.strip() for line in f]
14测试成功的Python中文文件读写脚本    for i in ls :
15测试成功的Python中文文件读写脚本         print i.encode('gbk')
16测试成功的Python中文文件读写脚本    f.close()
17测试成功的Python中文文件读写脚本fn='./intimate.txt'
18测试成功的Python中文文件读写脚本v_ls=[u"中文"]
19测试成功的Python中文文件读写脚本writefile(fn,v_ls)
20测试成功的Python中文文件读写脚本readfile(fn)
21测试成功的Python中文文件读写脚本
22测试成功的Python中文文件读写脚本#代码本身也要存成utf-8格式。
23测试成功的Python中文文件读写脚本
24测试成功的Python中文文件读写脚本

相关文章: