Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Using Databases in Python Our Diary App Switching It Up

Paul Bentham
Paul Bentham
24,090 Points

Name_Error on Switching it Up? 'a' is not defined... using terminal on Ubuntu.

When I run diary.py in terminal on Ubuntu I get a Name_Error when I type a or v. If I put them inside quotes I don't get the error?

I tried to get around this by putting str() around the input() but that didnt work.

Here is the terminal output:

office@Office-PC:~/Desktop/Database example$ python diary.py 
Enter 'q' to quit.
a Add an entry
v View previous entries
Action: a
Traceback (most recent call last):
  File "diary.py", line 51, in <module>
    menu_loop()
  File "diary.py", line 30, in menu_loop
    choice = str(input('Action: ').lower().strip())
  File "<string>", line 1, in <module>
NameError: name 'a' is not defined
office@Office-PC:~/Desktop/Database example$ 

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Guessing you're on Python 2.7 instead of 3.4 like we use for everything at Treehouse. You'll need to use raw_input() instead of input().