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

Python

value.__doc__ output is unusual

Issue: When printing the menu, instead of something like "a) Add entry", I get this: " a) str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'. "

Any tips please? Please note that I display the menu in a function which I call in the main while loop. I've included my code below:

def initialize():
    """ create  table if it donesn't exist"""
    db. connect()
    db.create_tables([Entries_table], safe=True)

def menu_loop():
    choice = None

    while choice != 'q':
        show_menu()
        print("Enter 'q' to quit.")
        choice = input("Action > ").lower().strip()

        if choice in menu:
            menu[choice]()

def add_entry():
    """ Add entry """

def delete_entry():
    """ Delete entry """

def search_entry():
    """ Search entries for... """
def view_entry():
    """ View entry """

def show_menu():
    for key, value in menu.items():
        print("{}) {}".format(key, value.__doc__))

menu = OrderedDict([
    ('a', 'add_entry'),
    ('d', 'delete_entry'),
    ('s', 'search_entry'),
    ('v', 'view_entry'),
])

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

1 Answer

Ha! solved my own problem - the values in the OrderedDict were in quotes. this is what was causing the issue. T/C