Python读写unicode文件 Python读写unicode文件的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Python读写unicode文件 Python读写unicode文件的方法

Sephiroth   2021-03-21 我要评论
想了解Python读写unicode文件的方法的相关内容吗,Sephiroth在本文为您仔细讲解Python读写unicode文件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Python,读写,unicode文件,下面大家一起来学习吧。

本文实例讲述了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程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们