Quinten (4) [Avatar] Offline

Thank you for writing this book. I am curious about the game aspect. I have a question. Could you give all of the code in one listing for test_todo.py and one listing for todo.py. This for survey.
Because i have some problems with them. They don't execute properly. For instance by running todo.py there is a nameError: " global name 'run_command' is not defined."
run_command(user_input) is a function?

anthony.briggs (30) [Avatar] Offline
Re: Survey_Chapter_4
Hi Quinten,

The first question I should ask is: what are your tests telling you? Are they passing, but you're still getting an error message when running todo.py?

There are a few possibilities, but the root cause of that error is that there's no 'run_command' defined at the point that you're trying to call it.

Is run_command defined before you're calling it? eg. if you have something like:
def run_command():
print "hello!"
Then you'll see the error message that you're getting. (If you're calling run_command() from inside a function you should be ok though)

One other possibility is that you've misspelled the name of the function, eg. trying to call run_command() when it's defined as run_commad - I've done that a few times myself.

Hope that helps,

Quinten (4) [Avatar] Offline
Re: Survey_Chapter_4
Hi Anthony,

I understand your remark and it was useful to some degree. In the def main_loop of todo.py you use:
print run_command(user_input) in a while loop and run_command is not defined before that loop. I don't know how to do that the way you mean.
Maybe you can mail the sourcecode of todo.py? Up to 4.4 the code of both programs were running correctly. I can't find the mistake after that.