Python: TypeError: 'list' object is not callable on global variable -


i in process of programming text-based adventure in python learning exercise. want "help" global command, stored values in list, can called @ (essentially) time. player enters new room, or options change, reset help_commands list new values. however, when debug following script, 'list' object not callable typeerror.

i have gone on code time , time again , can't seem figure out what's wrong. i'm new python, assume it's simple i'm overlooking.

player = {     "name": "",     "gender": "",     "race": "",     "class": "",     "hp": 10, }  global help_commands help_commands = ["save", "quit", "other"]  def help():     sub_help = '|'.join(help_commands)     print "the following commands avalible: " + sub_help   def help_test():     = ["exit [direction], open [object], talk [person], use [item]"]     print "before go further, i'd know little more you."     print "what name, young adventurer?"     player_name = raw_input(">> ").lower()     if player_name == "help":         help()     else:         player['name'] = player_name         print "it nice meet you, ", player['name'] + "."  help_test() 

edit:

you're python guru, moses. fixed problem, can't values in help_commands overwritten new commands:

player = {     "name": "",     "gender": "",     "race": "",     "class": "",     "hp": 10, }  # global help_commands help_commands = ["save", "quit", "other"]  def help():     sub_help = ' | '.join(help_commands)     return "the following commands avalible: " + sub_help   def help_test():     print help()     help_commands = ["exit [direction], open [object], talk [person], use [item]"]     print help()     print "before go further, i'd know little more you."     print "what name, young adventurer?"     player_name = raw_input(">> ").lower()     if player_name == "help":         help()     else:         player['name'] = player_name         print "it nice meet you, ", player['name'] + "."  help_test() 

thoughts?

you mixing name of list of function:

help = ["exit [direction], open [object], talk [person], use [item]"] 

and then:

def help():     sub_help = '|'.join(help_commands)     print "the following commands avalible: " + sub_help 

the name help in current scope (which references list) being treated callable, not case.

consider renaming list or better still, both, since name help being used builtin function.


Comments