|
发表于 2023-2-6 14:54:31
|
显示全部楼层
问答题:
0. 不会,会新增文件
1. 使用flush方法
2. 读取3个字符
3. 15个
4. 保存的时候,writelines将\n单独存为了一行
5. 没有用反斜杠转义反斜杠
6. 如果文件本身有内容的话,会清空
7. 不可以
8. 指向现在读取到的文件位置
9. End of the file文件末尾标识符
10. f.tell()
动动手:
0.
f1 = open("FishC.txt", "r")
content1 = f1.read()
f1.close()
f2 = open("FishD.txt", "w")
f2.write(content1[10: 15])
f2.close()
1.
f = open("FishC.txt", "r")
content = f.read()
f.close()
f1 = open("FishC.txt", "w")
f1.write(content[:15])
f1.close()
2.
f = open("open_myself.py", "r")
for each in f:
print(each)
f.close()
3.
f1 = open("target.zip", "r", encoding='gbk', errors='ignore')
content = f1.read()
f1.close()
f = open("test.jpg", "a")
f.write(content)
f.close() |
|