|
发表于 2022-12-14 16:16:59
|
显示全部楼层
问答题
0. 在特定模式下会报错,另一些模式下会创建文件
1. 不知道
2. 只读取3个字符
3. 一行,没有加换行符
4. 因为print()函数本身自带一个换行
5. 因为python中是用/来作为路径符号的,如果用反斜杠需要前面加r
6. w会将文件从头截断,原来的内容就没啦
7. 可以!
8. 确定读取和写入的位置
9. 相当于指针的位置
10. tell()
动动手
0. f = open(r'C:\Users\wanghuitian\Desktop\python_fish\FishC.txt', 'r')
f.seek(9)
a = f.read(6)
t = open(r'C:\Users\wanghuitian\Desktop\python_fish\FishD.txt', 'w')
t.write(a)
t.close()
1. f = open(r'C:\Users\wanghuitian\Desktop\python_fish\FishC.txt', 'r+')
f.seek(0)
a = f.read(15)
f.truncate(0)
f.write(a)
f.close()
2. f = open(r'C:\Users\wanghuitian\Desktop\python_fish\open_myself.py')
f.seek(0)
for each in f:
print(each, end='')
3. f = open(r'C:\Users\wanghuitian\Desktop\python_fish\hw\target.zip', 'rb')
a = f.read()
f.close()
t = open(r'C:\Users\wanghuitian\Desktop\python_fish\hw\test.jpg', 'a+b')
t.write(a)
t.close |
|