我遇到以下几行代码的问题:
Dictionary = {}
with open("Text Docs/clues.txt", "r") as l:
for l in clues:
Dictionary[l[0]] = Dictionary[l[1]]
收到错误消息:
(file location), line #, in function
for l in clues:
NameError: global name 'clues' is not defined
答案 0 :(得分:1)
你没有迭代文件对象,你可能意味着:
Dictionary = {}
with open("Text Docs/clues.txt", "r") as l:
for line in l:
...
答案 1 :(得分:1)
没有定义称为线索的变量。您创建的文件对象称为l。所以你的for循环应该迭代它。
使用:
for line in l:
#do something