Python 文件指针(光标)

file=open(r"C:\Users\Tsinghua-yincheng\Desktop\hcq.txt","r")

#file.seek(16,0)   #0文件调到从开头开始第十五个字符,一个换行符
mystr=file.readline() #读取英文,遇到换行符
print(file.tell())  #获取文件的指针位置(光标位置)
print(mystr)
#file.seek(0,0)    #跳转文件指针, 开头,第一个参数表示偏移量,第二个表示从文件开头开始偏移
file.seek(200,0)   
mystr=file.readline() 
print(mystr)
#print(len(mystr)) #求长度,不包含换行符
file.close()

你可能感兴趣的:(Python)