DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   Python (http://www.daniweb.com/forums/forum114.html)
-   -   problem with string (http://www.daniweb.com/forums/thread28688.html)

peaceofmind Jul 21st, 2005 7:13 pm
problem with string
 
hi :)
I need some help for this script
I have
--------------------
cursor = conn.cursor()
cursor.execute("select * from playlist limit 5")
result = cursor.fetchall()
# iterate through resultset
playlist_txt = ''
for record in result:
 mp3id = record[0]
 mp3_title = record[1]
 mp3_artist = record[2]
 playlist_txt += mp3id + mp3_title + mp3_artist
 #print mp3id , " - ", mp3_title , ' - ', mp3_artist , "<br />"
cursor.close()
conn.close()
------------------
#and want to print this out of "for record in result:"
print playlist_txt

#but there is an error in
playlist_txt += mp3id + mp3_title + mp3_artist

10x in advance :)))

Rashakil Fol Jul 21st, 2005 7:33 pm
Re: problem with string
 
With Python questions, you definitely need to use CODE tags.

peaceofmind Jul 21st, 2005 7:35 pm
Re: problem with string
 
sorry but I write here for the first time
Now I know 10x

vegaseat Jul 22nd, 2005 9:00 am
Re: problem with string
 
Can you give us the error message and a little more of your code?

Without that info, I don't know what your resultset looks like. I can only assume that mp3id could be an integer and needs to be converted to a string to work with the + concatination. In this case mp3id = str(record[0]) would do the trick.

peaceofmind Jul 22nd, 2005 10:02 am
Re: problem with string
 
10x for the help
I try with this and it work perfect :))
 
 playlist_txt += str(mp3id) +  str(mp3_title) + str(mp3_artist) + '<br>'
 #playlist_txt += "%s %s %s <br>" % (mp3id, mp3_title, mp3_artist)

Edit: added / to ending [/code]


All times are GMT -4. The time now is 2:29 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC