首页 > 编程语言 > 详细

Python开发【第三章】:Python的文件操作

时间:2016-08-08 17:20:22      阅读:262      评论:0      收藏:0      [点我收藏+]

Python的文件操作

一、读取操作,3种读取方式的区别

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#-Author-Lian
info_file = open("here_we_are",encoding="utf-8")    #默认读取模式
print(info_file)                                    #不加参数,直接打印
#<_io.TextIOWrapper name=‘here_we_are‘ mode=‘r‘ encoding=‘utf-8‘>

#print(info_file.read())                            #read参数,读取文件所有内容
#我越无所适从
#越会事与愿违
#在交错的时空
#灵魂加速下坠
#Here we are, here we are, here we are

#print(info_file.readline())                        #readline,只读取文章中的一行内容
#我越无所适从

print(info_file.readlines())                        #readlines,把文章内容以换行符分割,并生成list格式,数据量大的话不建议使用
#[‘我越无所适从\n‘, ‘越会事与愿违\n‘, ‘在交错的时空\n‘, ‘灵魂加速下坠\n‘, ‘Here we are, here we are, here we are\n‘]

  

Python开发【第三章】:Python的文件操作

原文:http://www.cnblogs.com/lianzhilei/p/5749932.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!