Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project4/step_3: "bill" not defined #25

Closed
jtmx opened this issue Jun 17, 2015 · 2 comments
Closed

project4/step_3: "bill" not defined #25

jtmx opened this issue Jun 17, 2015 · 2 comments
Labels

Comments

@jtmx
Copy link

jtmx commented Jun 17, 2015

Line 28: for bill in objects:...
The error message "bill not define" results after I put in the command.
We do have the bills.json and bills.csv files, but no "bill" variable. Thoughts?

@tommeagher
Copy link
Collaborator

Jenny, sorry for the delay in responding to this. Are you saving this code in a script that you run from the command line, or are you typing them one line at a time in the interactive interpreter?
Either way, can you share your code in the lines before this? My guess is something got mistyped along the way. When I run this with python step_3_complete.py, everything works as expected.

But to your question on the "bill" variable: That's kind of an oddity of python that confused me initially. You don't need to declare that variable before you start your for loop. Using the for syntax indicates that you're about to loop through an iterator, and bill is a variable you create on the fly that refers to each item in the iterator (in this case, the objects list) each time you cycle through it. You could name it anything you want. You could call it sam or o or cheesesteak. The name doesn't really matter, provided you use that same name when referring to the individual objects in the lines that follow the for loop's start.

I hope that makes sense. Maybe @katiepark or @kevinschaul can explain it better. Either way, if you're still having trouble, share all your code in this thread, and we can help you debug it.

@jtmx
Copy link
Author

jtmx commented Jun 28, 2015

Thanks Tom. Your explanation helped.

Yup, you're right - just a typo on my part. Now everything works.

@jtmx jtmx closed this as completed Jun 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants