2021-08-26 Python文件打开

#文件操作:
'''
buffering 缓存
mode:read,write,binary
chunks 块,片
interactive 交互
append 追加

系统函数:
open(file,open,buffering,encodeing)

open(path/filename,'rt') --->返回值:stream(管道)
container=stream.read() --->读取管道中的内容

注意:如果传的path/filename有误,则会保错,FileNotFoundError
'''

1 stream=open(r'C:\pl\aa.txt')
2 container=stream.read()
3 print(container)
4 result=stream.readable()   #判断是否可以读取 True False
5 print(reault)
6 
7 lines=stream.readlines()     #保存到列表
8 print(lines)

'''
如果传递的path/filename有误,则会报错:filenotfounderror
如果是图片则不能使用默认的读取方式mode:'rb'
'''
'''
总结:
read() 读取所有的内容
readline() 每次读取一行内容
readlines() 读取所有的行保存到列表中
readable() 判断是否可读的
'''

 

posted @ 2021-08-26 14:40  admin-xiaoli  阅读(62)  评论(0编辑  收藏  举报