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

Daniel Tompkins
Daniel Tompkins
5,591 Points

I'm struggling to figure out a way of passing "clear()" while keeping messages like "Entry saved!" etc.

diary.py

It bothers me that we lose important feedback from the program like "Entry saved!" and "Entry was deleted successfully!". Is there a way that we don't have to compromise the clean interface "clear()" gives us with each action for these feedback messages?

CODE EXAMPLE:

def view_entries(search_query=None):

"""View previous entries."""
entries = Entry.select().order_by(Entry.timestamp.desc())
if search_query:
    if Entry.content.contains(search_query):
        entries = entries.where(Entry.content.contains(search_query))
    else:
        print("Entry does not exist. Check for mispelled words and try again!")
for entry in entries:
    timestamp = entry.timestamp.strftime('%A %B %d, %Y %I:%M%p')
    clear()
    print(timestamp)
    print('='*len(timestamp))
    print(entry.content)
    print('\n\n'+'='*len(timestamp))
    print('n) next entry')
    print('d) delete entry')
    print('q) return to main menu')
Steven Parker
Steven Parker
228,991 Points

To enable accurate and complete answers, always show your code and also provide a link to the course page you are working with.

Daniel Tompkins
Daniel Tompkins
5,591 Points

Another method, defining "add_entry", would print a message with feedback saying "Your entry has been saved!" or a similar note. However, the video lesson suggested putting "clear()" to clean up the console space. I'm just wondering if there's an easy way to avoid having those feedback messages removed while keeping the interface clean?