I have the following problem where
roles = models.StringField
def role(player):
if player.rank == 1:
return 'leader'
else:
return 'member'
Later I am trying to assign the role function outcome which is string to roles variable i.e.
for i in range(len(players)):
players[i].roles = players[i].role()
.....
However, I am getting the message that str function is not callable. I am new to python programming. Any help will be much appreciated. The function is working properly otherwise. I am using python 3.9.
I have used the setattr
function by trying
for i in range(len(players)):
name = 'roles'
setattr(players[i], name, players[i].role())
.....
However, still I am getting the same message that str function is not callable. Any idea how can I fix this.
this error msg is a runtime error.
it means that
players[i].role
is a string not a function. that means that somewhere is your app, you assigned a string value toplayers[i].role
. so it is no longer a function.this may be a typo (ie: you probably wrote
players[i].role = "blabla bla"
instead of
players[i].roles = "blabla bla"
)