[Tutor] Newbie append puzzle

Tim Ronning tim.ronning at start.no
Sun Nov 2 10:43:22 EST 2003


Hi you all

The following code is a part of my first thumbeling steps into the world of 
Python. It's a simple mp3 player.

- - - - Cut - - - - - - - - - - - - -

	elif choice == '3': # Add to an existing list
        def append(mp3):
           app = open("playlist","a")
           app.write(mp3)
           app.close()
        newmp3 = raw_input("New mp3: ")
        append(newmp3)

	elif choice == '4': # Make an int. list, deletes, makes a new playlist, 
and copies itself to playlist
        def makeaList(s):
            anothermp3 = string.split(s)
            return anothermp3

        playlist = open("playlist","r")
        mp3list = []
        for line in playlist.readlines():
            mp3list = mp3list + makeaList(line)

        playlist.close()
        delnr = int(raw_input("Which number? "))
        del mp3list[delnr]
        listlen = len(mp3list)

        def append(mp3):
           app = open("playlist.new","a")
           app.write(mp3)
           app.close()
        n = 0
        while n < listlen:
            append(mp3list[n])
            n = n + 1
- - - - - Cut - - - - - - - - - - -  - -

The problem: The append() function under choice "3" appends the raw_input 
on a new line in the playlist file. Simple ascii. This is correct. The 
append() function under choice "4" appends all the list items on one single 
line without spaces, this is not what I want. I want them on separate 
lines. I have a feeling the answer is embarasing simple and probably 
steering me right in the face, but somehow I don't see it. Anyone?

Best regards

Tim Ronning

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/



More information about the Tutor mailing list