001、文件对象read读入文件
>>> in_file = open("a.txt", "r") >>> in_file.read() ## 'abcd\nefgh\ni\n'
002、文件对象tell 返回指针再文件中的位置
>>> in_file = open("a.txt", "r") ## 打开文件 >>> in_file.tell() ## 返回文件指针当前的位置 0 >>> in_file.read() ## 读入文件 'abcd\nefgh\ni\n' >>> in_file.tell() ## 返回指针当前的位置 12
003、文件对象seek移动指针
>>> in_file = open("a.txt", "r") ## 打开文件 >>> in_file.tell() ## 返回当前指针 0 >>> in_file.read() ## 读入文件 'abcd\nefgh\ni\n' >>> in_file.tell() ## 返回当前指针位置 12 >>> in_file.seek(5,0) ## 从0开始偏移5 5 >>> in_file.tell() ## 返回当前指针位置 5 >>> in_file.read() ## 从指针位置读入文件 'efgh\ni\n'
004、设定读入的字符数目
>>> in_file = open("a.txt", "r") ## 打开文件 >>> in_file.read(5) ## 读入5个字符 'abcd\n' >>> in_file.tell() ## 返回当前指针的位置 5
。