擅长:python、mysql、java
<p>你指出问题是对的。你知道吗</p>
<p>您需要清空变量:</p>
<pre><code>d
</code></pre>
<p>每次你循环。你知道吗</p>
<p>示例:</p>
<pre><code>d={}
while True:
try:
filename=input("Enter the name of the file to open: ") + ".txt"
with open(filename,"r") as f:
for line in f:
splitLine=line.split()
d[splitLine[0]]=splitLine[1:]
print(line, end="")
d={}
break
except FileNotFoundError:
print("File name does not exist; please try again")
</code></pre>