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 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?