Python Using Databases in Python Our Diary App Switching It Up

Dara Roberts
PRO
Dara Roberts
Pro Student 7,770 Points

Name error persisting after moving OrderedDict to the bottom of file

After moving the OrderedDict to the bottom of the file

menu = OrderedDict([
    ('a', add_entry),
    ('v', view_entry),
])

if __name__ == '__main__':
    initialize()
    menu_loop()

My command line returns this error:

Action: a
Traceback (most recent call last):
  File "diary.py", line 56, in <module>
    menu_loop()
  File "diary.py", line 31, in menu_loop
    choice = input('Action: ').lower().strip()
  File "<string>", line 1, in <module>
NameError: name 'a' is not defined

3 Answers

Miguel Boekhold
Miguel Boekhold
7,217 Points

Ah, apparently this is an issue pre Python 3.x, Python2's input read and evaluates what you put into it, in this case looking to return a variable we put into the input() , in python2 you would need to do raw_input(), python3 does not have this behavior

Miguel Boekhold
Miguel Boekhold
7,217 Points

I have the same issue, is there anyone who can explain why?

Dara Roberts
PRO
Dara Roberts
Pro Student 7,770 Points

Yeah I completely forgot to respond to my own question by mentioning the switch to python 3 that helped fix it. Sorry!