Python读写unicode文件的方法
2015-07-10 00:00
861 查看
本文实例讲述了Python读写unicode文件的方法。分享给大家供大家参考。具体实现方法如下:
#coding=utf-8 import os import codecs def writefile(fn, v_ls): f = codecs.open(fn, 'wb', 'utf-8') for i in v_ls: f.write(i + os.linesep) f.close() def readfile(fn): f = codecs.open(fn,'r','utf-8') ls = [ line.strip() for line in f] f.close() for i in ls: print i if __name__ == '__main__': fn = u'11.txt' ls = [u'1.python', u'2.how to pythonic', u'3.python cook', u'python编程'] writefile(fn, ls) readfile(fn)
希望本文所述对大家的Python程序设计有所帮助。
相关文章推荐
- Python实现telnet服务器的方法
- Python实现大文件排序的方法
- Python实现的最近最少使用算法
- python实现中文分词FMM算法实例
- Python获取邮件地址的方法
- Python自动登录126邮箱的方法
- Python将阿拉伯数字转换为罗马数字的方法
- Python写入数据到MP3文件中的方法
- Python实现分割文件及合并文件的方法
- python subprocess使用记录
- python语法练习
- Python 3 抓取百度贴吧图片
- Python IDLE中实现清屏
- 一个WXPython+采集的 Demo
- python入门知识
- Python中的__new__()方法与实例化
- Python基本语法
- Python对象(下)
- 《python核心编程》读书笔记——列表解析
- yiled in python