标签:
一、读取操作,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‘]
标签:
原文地址:http://www.cnblogs.com/lianzhilei/p/5749932.html