Results 1 to 2 of 2

Thread: Saving a list to file

  1. #1
    Verified Registered User davorp's Avatar
    Join Date
    Aug 2005
    Posts
    125
    Thanks
    61
    Thanked 48 Times in 30 Posts

    Saving a list to file

    Hello,

    I am writing a small program in python which is a list of my favourite anime. Now, I would like to save the list to file.

    This is my code:

    Code:
    myanime=[]
    for _ in range(10):
        myanime.append(input("Enter a new entry :"))
        print('My Favourite anime: \n'  ,  *myanime, sep='\n - ')
    This creates a list from the input value. I would now like to save the list to a file, after all the ten entries were added. I have tried with pickle, but it didnít do what I wanted. How can I save my list to a file? Thank you.

  2.    Advert



  3. #2
    Super Moderator saintomer1866's Avatar
    Join Date
    Sep 2005
    Posts
    3,522
    Thanks
    4,700
    Thanked 7,989 Times in 2,440 Posts
    something like this should work
    Code:
    myanime=[]
    for _ in range(10):
        newEntry = raw_input("Enter a new entry :")
        print "My Favourite anime: \n" + newEntry + "\n - "
        myanime.append(newEntry)
    f= open("myanime.txt","a+")
    for item in myanime:
        f.write("%s\n" % item)
    f.close()
    St.O

  4. The Following User Says Thank You to saintomer1866 For This Useful Post:

    davorp (18-04-2018)

Similar Threads

  1. usb stick issues saving ch list etc ?
    By tybusta1 in forum Spiderbox 6000 HD
    Replies: 24
    Last Post: 23-06-2014, 12:14 PM
  2. saving channel list
    By league in forum 5000 series
    Replies: 8
    Last Post: 14-02-2014, 09:19 AM
  3. which file holds transponders list plz
    By iwols in forum Vu+ Duo2 Help Section
    Replies: 4
    Last Post: 14-11-2013, 02:41 PM
  4. Saving Channel List
    By Grahamc in forum 6000 series
    Replies: 1
    Last Post: 14-01-2012, 09:31 AM
  5. new channel list not saving
    By wwe in forum Dreambox DM800HD
    Replies: 0
    Last Post: 16-09-2008, 12:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •