文件操作之读取文件

#文件操作
'''
文件上传:
保存log
系统函数:
open(file,mode,buffing,encoding)
读:
    open(path/filename,'rt')------>返回值: stream(管道)
    container=stream.read()------>读取管道中的内容
    注意:如果传递的path/filename有误,则会报错:FileNotFoundError
    如果是图片则不能使用默认的读取方式,mode='rb'

    总结:
    read()       读取所有文件
    readline()  每次读取一行的内容
    readlines() 读取所有的行保存到列表中
    readable()  判断是否是可读的
'''
stream=open(r'C:\Users\Administrator\Desktop\p1\aa.txt')
# container=stream.read()
# print(container)
# result=stream.readable()
# print(result)
# while True:
#     line=stream.readline()
#     print(line)
#     if not line:
#         break

lines=stream.readlines()   #保存在列表中
print(lines)
for i in lines:
    print(i)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值