0
点赞
收藏
分享

微信扫一扫

python基础复习(17)--文件指针

waaagh 2022-07-13 阅读 67


#文件指针
#tell获取当前文件指针
fobj=open("./abcde.txt","wt")
print(fobj.tell())
fobj.write("abc")
print(fobj.tell())
fobj.close()

# rt+  wt+  at+允许移动文件指针  seek(offset,whence)   offset偏移量  whence  默认0从文件开始算起  1从当前位置算起  2从文件末尾算起
def writeFile():
fobj=open("./cc.txt","wt+")
print(fobj.tell())
fobj.write("123")
print(fobj.tell())
fobj.seek(1,0)
print(fobj.tell())
fobj.write("abc")
print(fobj.tell())
fobj.close()

def readFile():
fobj=open("./cc.txt","rt+")
rows=fobj.read()
print(rows)
fobj.close()

try:
writeFile()
readFile()
except BaseException as err:
print(err)


举报

相关推荐

0 条评论