Python 文件操作

f=open ('test.log','w')

f.write('aaabbssss')

f=open ('test.log','r')

printf(f.tell())----------------0(字节)查看指针位置

ret=f.read(2)//读两个字符------指定读取字符

printf(f.tell())----------------4

f.seek(2)---设置指针位置

f.close()

print(ret)------------------aa

f.seek(5)

print(f.read())-------------------ssss

f=open ('test.log','r+')

f.truncate(5)------保存指针5以前的在记事本中

原文地址:https://www.cnblogs.com/my334420/p/6364548.html