|  | 
 
 发表于 2024-2-17 08:46:22
|
显示全部楼层 
| 不会 f.flush()
 每一行读取3个字符
 print()自带一个换行符
 文件中存在无法解码的字符
 不要马上用close()关闭,会截断
 可以
 定位字符
 文件末尾
 f.tell()
 
 f=open("D:\\03 Python\Program6\FishC.txt",'r')
 g=open("D:\\03 Python\Program6\FishD.txt",'w')
 f.seek(10)
 a=f.read(5)
 g.write(a)
 g.close()
 f.close()
 
 f=open("D:\\03 Python\Program6\FishC.txt",'w')
 f.truncate(15)
 f.close()
 
 f=open("D:\\03 Python\Program6\open_myself.py",'r')
 for each in f:
 print(each,end='')
 
 f=open("D:\\03 Python\Program6\\test.jpg",'a')
 g=open("D:\\03 Python\Program6\\target.zip",'r')
 f.seek(0, 2)
 g.seek(0,0)
 a=g.read()
 f.write(a)
 | 
 |