当我发现这个错误时,我正在尝试做一些代码。我首先用a和定义player
类。当我运行该函数并尝试在其中创建
类的实例时,出现错误。这是我的代码:name
param1
param2
game
player
UnboundLocalError
class player(object):
def __init__ (self, name, param1 = None, param2 = None):
self.param1 = param1
self.param2 = param2
self.name = name
def game(n = int(raw_input('How many players? '))):
playerList = []
for x in range(n):
playerList.append(player(raw_input('Player %i: ' %(x+1))))
for player in playerList:
player.param1 = int(raw_input('%s, how many do you predict? ' %(player.name.upper())))
所以基本上,我的问题是python不允许我在函数中创建类的实例。我已经搜索了很多,但我没有找到我要搜索的内容。提前致谢!