Python 移动光标位置

x = file('1.txt','r')
print x.tell() #显示当前光标位置


x.seek(3)
print x.tell() #没有设置光标位置,默认从头开始移动3个位置


x.seek(5, 1)
print x.tell() #从当前开始移动5个位置


x.seek(2, 2)
print x.tell() #从末尾开始向前移动2个位置

猜你喜欢

转载自blog.csdn.net/liuyudong_/article/details/80250105