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 extra credit problem

i did the extra credit for the shopping list project but when i check the file i created for the list, the list horizontal not vertical like a list, how can i make it vertical?

2 Answers

Freddy Venegas
Freddy Venegas
1,226 Points

I did this like so,

def open_save():
    with open('list.txt', 'w') as l:
        for items in shopping_list:
            l.write(str(items) + "\n")

and that seemed to work. By adding the "\n" you create a new line.

Out of curiosity, how did you get the contents from the file to read into your list when the file first runs? I am stuck on that step.

def open_save():
  print("enter the name of your file")
  file = input('Enter your name: ')

       with open(file, 'w') as file:
         for items in shopping_list:
            file.write(str(items) + "\n")
    print("try again")

try my code it completely works, just add the .txt when u name your file like "name.txt", and thanks btw it really helped me.

What does your print statement look like?