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

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
220,937 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?