|  | 
 
 发表于 2024-1-9 15:49:09
|
显示全部楼层 
| 0. 不会报错,会创建一个新的文件 1. f.flush()
 2. 读取三个字符
 3. 一行
 4. 因为执行了两次打印操作,每次打印操作会默认生成一个换行
 5. 因为路径中的\被当成转义字符了
 6. 要注意文件内容已经保存过了
 7. 可以
 8. 很多文件方法需要指针来提供开始或者结束
 9. end of the file,文件末尾
 10. f.tell()
 
 
 0.
 f = open("FishC.txt", "r+")
 f.truncate(15)
 f.seek(10)
 s = f.read()
 f.close()
 
 f = open("FishD.txt", "w")
 f.write(s)
 f.close()
 
 
 1.
 f = open("FishC.txt", "r+")
 f.truncate(15)
 s = f.read()
 f.close()
 f = open("FishC.txt", "w")
 f.write(s)
 f.close()
 
 
 2.
 f = open("open_myself.py", "r")
 for each in f:
 print(each)
 f.close()
 
 
 3.
 f = open("test.jpg", "r+")
 f2 = open("被隐藏的文件.txt", "r+")
 s = f2.read()
 f.write(s)
 f.close()
 f2.close()
 
 
 | 
 |