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 Python Basics (2015) Shopping List App Second Shopping List App

How to save file for shopping list app Open/Close File Bonus challenge?

Hello I tried to do the open/close block. It ran ok and didn't show any error. However, when I checked my shopping_list.txt none of the items were saved. Also, can someone one please explain the closing block that I wrote. I got it off of youtube, but the source did not explain what this does:

except Exception as e: print(e) https://gist.github.com/07fca53d160f12caa7de7a0fbe4e40aa thank you

1 Answer

Steven Parker
Steven Parker
229,732 Points

The program is calling the "open_save" function as it starts up, before any items have been read. So it creates an empty file.

You probably want to call "open_save" at the end of the program instead, to save the items.

Then you might want to add some code to read the items back in when the program starts (there's nothing like that in the code now).