【发布时间】:2018-03-26 04:35:48
【问题描述】:
def __init__(self):
#self.data = []
self.random_word = random.choice(open("EnglishDictionary.txt").readlines()).strip()
self.length_notice = "The word you're guessing is {} letters long.".format(len(random_word))
这只是返回错误:Name 'random_word' is undefined
【问题讨论】:
-
您可以让 init 调用一个函数,并传入您生成的 random_word。
标签: python python-3.x variables scope initialization