Python忽略了Python while循环错误条件?

2024-05-15 07:40:25 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我正在运行的代码:

#Import torsions.dat
f = open("torsions.txt")
next = f.readline().strip()
length = next                       #Store the first line as length

#Store the values for phi and psi in lists
phi = []
psi = []
while next != "":
    next = f.readline().strip().split(" ")
    phi.append(float(next[0]))
    psi.append(float(next[1]))

但我有个错误:

enter image description here

文件扭转.txt包含以下内容:

20个

60 61岁

62 63个

64 65岁


65后没有空格。后面有4行(即中间没有空行)。下划线只是为了清楚起见,它们不在文本中。你知道吗

由于错误,循环停止了脚本,并且循环后的部分没有运行。 phi和psi按要求填充,但是循环应该停止,但是看起来没有

你能帮忙吗?你知道吗


Tags: thestore代码importtxtreadline错误float