文件定位

filename = "./by.txt"
objFile = open(filename,"r+") #需要从末尾定义时,须使用“rb”模式
# 读取5个 .read
str = objFile.read(5)
print("当前字符串读取的为:",str)
# 指出当前光标位置 .tell
posi = objFile.tell()
print("光标当前的位置是:",posi)
# 重新把光标定位到某个位置 .seek(0,0)
position = objFile.seek(2,0)
print("重新把光标定义的位置:",position)
str = objFile.read(20)
print("当前字符串:",str)

猜你喜欢

转载自www.cnblogs.com/byh7595/p/11966305.html
今日推荐