windows下python3.7.0使用readlines()时报错:IndexError: list index out of range

tech2025-11-18  1

IndexError: list index out of range

使用open打开txt文件,文件内容就一行数字` 具体代码如下:

with open("***.txt","w") as f: with open(i) as f_t: print(len(f_t.readlines())) print(ft.readlines()) label=f_t.readlines()[0].strip()

readlines()会返回一个list,当打印其长度并正常的显示1。紧接着再打印list内容时就为空了,why?

当去掉第一个print语句,就能正常打印出list中内容,这是bug吗?

最新回复(0)