|
发表于 2022-10-29 16:02:44
|
显示全部楼层
问答题:
0. 不会,会生成一个文件
1. 使用flush()方法
2. 表示只读取3个字符
3. 一行
4. 多出来的是print函数默认的 end='\n'
5. 字符串中'\'为转义字符,输入路经时应在字符串前加上'r'
6. 注意文件内无内容,否则可能会被截断
7. 可以
8. 确定读写文件时的位置
9. end of file,文件结束的位置
10. 使用tell()方法获取
动动手
0.
f = open('FishC.txt', 'r')
nf = open('FishD.txt', 'w')
f.seek(10)
nf.write(f.read(5))
f.close()
nf.close()
1.
f = open('FishC.txt', 'a')
f.truncate(15)
f.close()
2.
f = open('open_myself.py', 'r')
for each in f:
print(each)
f.close()
3.
tupian = open('test.jpg', 'a')
yasuobao = open('target.zip', 'r')
tupian.write(yasuobao.read())
tupian.close()
yasuobao.close()
|
|