Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Switching up: diary.py - Why am I getting this comments on the console?

My question is when I start ./dairy.py it doesn't give me a clean console options that should b option 'a' and 'w'. It returns a long text explaining what the values are going to be like. Any idea? Is this a bug in my code? Here is what I've done:

    #!/usr/bin/env python3

    from collections import OrderedDict
    import datetime

    from peewee import *

    db = SqliteDatabase('diary.db')

    class Entry(Model):
        content = TextField()
        timestamp = DateTimeField(default=datetime.datetime.now)

        class Meta:
            database = db

    def initialize():
        db.create_tables([Entry], safe="True")

    def menu_loop():
        """nothing yet"""
        choice = None

        while choice != 'q':
            print("Enter 'q' to quit.")
            for key, value in menu.items():
                 print('{}) {}'.format(key, value.__doc__))
            choice = input('Action: ').lower().strip()

            if choice in menu:

    def add_entry():
        """nothing yet """

    def view_entries():
        """nothing yet """

    def delete_entry(entry):
        """nothing yet """

    menu = OrderedDict([
        ('a', 'add_entry'),
        ('w', 'view_entries'),

    if __name__ == '__main__':
Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

It would help to read your code if you wrapped your code example in a <code>```python<code> ... <code>```<code> as mentioned in the Markdown Cheatsheet. Thanks!

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

The issue is with your menu definition. The second value of the tuple is expected to be a function, not a string. That is, remove the single quotes wrapping the function names:

menu = OrderedDict([
    ('a', add_entry),
    ('w', view_entries),

Trying to evaluate the code 'add_entry'.__doc__ results in a long output string instead of the doc string of the specific function:

In [116]: 'add_entry'.__doc__
Out[116]: "str(object='') -> string\n\nReturn a nice string representation of the object.\nIf the argument is a string, the return value is the same object."

Verses doing the same on the function, yeids the doc string:

In [117]: def add_entry():
   .....:         """nothing yet """

In [118]: add_entry.__doc__
Out[118]: 'nothing yet '

Thanks for the help. I couldn't see what the problem was.