我在测试filestreams在Python中的工作原理,我写了一些代码如下:
with open('test2.txt') as f:
while r := f.read(1):
print(repr(r), f.tell(), sep='\tindex:', end='\n***************\n')
test2.txt内容如下:
012345
6789
我运行了代码,输出如下:
'0' index:1
***************
'1' index:2
***************
'2' index:3
***************
'3' index:4
***************
'4' index:5
***************
'5' index:18446744073709551623
***************
'\n' index:8
***************
'\n' index:10
***************
'6' index:11
***************
'7' index:12
***************
'8' index:13
***************
'9' index:14
***************
请有人帮助我理解为什么f.tell()
返回18446744073709551623,以及为什么如果我们假设"5"得到索引6,为什么"\n"有索引8而不是7.先谢谢你.