无法调用导入列表:TypeError: 'list' object is not callable 问题求助
解决TypeError: 'list' object is not callable错误(Hangman游戏导入列表问题)
错误根源
你代码里的这行是问题核心:
words_list = hangman_words.word_list()
hangman_words.word_list本身就是一个列表对象,不是可调用的函数,你给它加了括号(),相当于试图把列表当成函数执行,所以触发TypeError: 'list' object is not callable。
修复方法
直接去掉括号,引用列表本身即可:
words_list = hangman_words.word_list
修正后的核心代码片段
#Step 5 import hangman_words import hangman_art import random #TODO-1: - Update the word list to use the 'word_list' from hangman_words.py #Delete this line: word_list = ["ardvark", "baboon", "camel"] # 去掉括号,直接引用列表 words_list = hangman_words.word_list chosen_word = random.choice(words_list) word_length = len(chosen_word)
你之前尝试赋值给变量仍报错,应该是没去掉括号——只要保留(),不管怎么赋值,本质都是在错误地调用列表对象,所以错误不会消失。
内容的提问来源于stack exchange,提问作者liamxgames
相关产品推荐
相关产品推荐

