Python文本操作---文件指针

1.seek():跳到指定的文件位置

# coding:utf-8


# 如果没有这个文件,新建一个文件,文件名为:myAllfile.txt
fileOpen = open("D:\pythonText\myAllfile.txt", "r")


if __name__ == '__main__':

     #file.seek(16,0) #0文件调到从开头开始第十五个字符,一个换行符
    mystr=file.readline() #读取英文,遇到换行符
    print(mystr)
    #file.seek(0,0) #跳转文件指针, 开头
    file.seek(200,0) #io.UnsupportedOperation: can't do nonzero end-relative seeks
    mystr=file.readline() #读取英文,遇到换行符
    print(mystr)
    #print(len(mystr)) 求长度
    file.close()

你可能感兴趣的:(Python)