[Tutor] Newbie append puzzle

Tim Ronning tim.ronning at start.no
Sun Nov 2 12:01:29 EST 2003


BTW. My Opera mail reader/writer is messing up indentation somehow.

Let's try this.

elif choice == '3':

	def append(mp3):
           		app = open("playlist","a")
           		app.write(mp3)
          		app.close()
        	newmp3 = raw_input("New mp3: ")
	append(newmp3)

elif choice == '4':

	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

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



More information about the Tutor mailing list