'''文件上传 保存log 系统函数: open(file,mode,buffering,encodeing) 读: open(path/filename,'rt')---->返回值:stream (管道) container = stream.read() ---->读取管道中内容 注意: 如果传递的path/filename有误,则会报错:FileNotFoundError 如果是图片则不能使用默认的读取方式,mode = 'rb' 总结: read() 读取所有内容 readline() 每次读取一行内容 readlines() 读取所有的行保存到列表中 readable() 判断是否可读的''' file=open(r'C:\\Users\\86159\\Desktop\1.txt','rb') print(file.readable()) container=file.readlines() print(container) for i in container : print(i) # 写文件 ''' stream = open(r'c:\p1\aa.txt', 'w') mode 是’w‘ 表示就是写操作 每次都会将原来的内容清空, 方法: write(内容) 然后写当前的内容 writelines(Iterable) 没有换行效果 stream.writelines(['赌神高进\n', '赌侠小刀\n', '赌圣周星星\n']) ---》自己加 如果mode='a' ''' file1=open(r'C:\\Users\\86159\\Desktop\1.txt','a') container=file1.write('我最帅') container=file1.writelines(['帅啊\n','太帅了\n']) file.close()
python爬虫的文档基本写入与读取
于 2022-03-25 17:22:20 首次发布