我需要做一個函數,返回基於數字列表的文件中的某些行,但我一直在收到ValueError: Mixing iteration and read methods would lose data.
有什麼建議嗎?Python for Value循環中的ValueError
with open(path) as f:
for line in f:
if i in lst:
a = f.readline()
ans += [a.strip()]
i += 1
else:
f.readline()
i += 1
一行3,'我'是什麼? – pylang
變量從0開始 – dguo52001
我有一個文本文件和一個數字列表。我只需要返回與這些數字對應的行。 – dguo52001