|
发表于 2023-11-13 10:47:55
|
显示全部楼层
- 0. 会报错
- 1. 有,用.flush()
- 2. 代表从第4个字符开始读取
- 3. 一行
- 4. 留白
- 5. 留白
- 6. 得注意文档是否是空的,如果非空会将内容清空
- 7. 不可以,追加模式得先有文档
- 8. 文件指针的作用是告诉操作者当前的位置,以方便后续的操作
- 9. end of the file ,文档结束了,读完了
- 10. tell()方法可以知道指针位置
- 动手题:
- 0.
- f = open("FishC.txt", "r+")
- f.seek(10)
- new_write = f.read(5)
- fd = open("FishD.txt", "w")
- fd.write(new_write)
- fd.close()
- 1.
- f = open("FishC.txt", "r+")
- f.truncate(15)
- f.close()
- 2.
- def open_myself():
- f = open("open_myself.py", "r")
- print(f.read())
- f.close()
-
- open_myself()
- 3.
- fj = open("test.jpg", "b")
- fz = open("test.zip", "r+")
- fj.write(fz.read())
- fj.close()
复制代码 |
|