之前写的整理文件格式脚本就出现过这个问题,今天特地做了个测试,本来想弄清出错的位置现在彻底懵了,求大佬解释。
0.用一个简单的python程序生成一个短的特殊文本。
test = open('','w',encoding = 'utf8')
for i in range(10):
i = str(i)
('读取进度')
(i)
('\n')
()
输出结果
读取进度0
读取进度1
......(此处省略)
读取进度9
ps:这种文本好看出读取进度
1.把文档用逐行读取的方式读取并打印。
test = open('','r',encoding = 'utf8')
()
end = ()
(0,0)
while () < end:
temp = line()
temp = str(temp)
print(temp)
()
输出结果
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
================== RESTART: C:\Users\hjli\Desktop\test\test.py =================
读取进度0
读取进度1
......(此处省略)
读取进度9
>>> ()
150
ps:读取打印正常,指针位置正常
2.逐字读取。
ps:把之前的line()改成了(1)
test = open('','r',encoding = 'utf8')
()
end = ()
(0,0)
while () < end:
temp = (1)
temp = str(temp)
print(temp)
()
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
================== RESTART: C:\Users\hjli\Desktop\test\test.py =================
读
取
进
度
0
读
取
进
度
1
......(此处省略)
读
取
进
度
9
>>> ()
150
ps:运行结果如下,输出结果正常,查看指针位置正常。
看完这两个结果我以为以前是我写的有bug,于是我生成了个更长的文本传进去。
这是readline的结果
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
================== RESTART: C:\Users\hjli\Desktop\test\test.py =================
读取进度0
读取进度1
......(此处省略)
读取进度999
>>> ()
16890
ps:这么长也没问题
但是之后逐字读就出问题了
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
================== RESTART: C:\Users\hjli\Desktop\test\test.py =================
读
取
进
度
0
读
取
进
度
1
......(此处省略)
读
取
进
度
4
8
6
>>> ()
18446744073709559784
ps:不但没读到999的位置,指针也出问题了
指针这莫大我感觉是系统出问题了。
各位有python的朋友可以回去用这个程序试试,如果有懂的大佬求个解答!!谢谢
ps:本问题已经在python论坛提问,在这里发的原因主要是想广撒网看看能不能捞到大佬。