[Tutor] cannot concatenate str with tuple obj

Conrad Koziol arkamir at softhome.net
Thu Oct 23 18:47:07 EDT 2003


When I try to execute the code below i get a 'cant concanate str with
tuple object', and i dont know how to fix it. Though when i print out
postinfo contents it seems to me like they are a string object Any help
would be appreciated. :) 


import MySQLdb
import re
db = MySQLdb.connect(host='localhost', user='conrad', passwd='evil'\
db='cgi')

cursor = db.cursor()

def retrieveposts(forum, thread):
	giventemplate = 'posttemplate'
	inputtemplate = open(giventemplate, 'r')
	posttemplate = inputtemplate.read()
	cursor.execute('''select names, subjects, posts, positions\ from %s
where threads =\'%s\'''' % (forum, threads))
	postsinfo = cursor.fetchall()
	#sort postsinfo by column positions
	posts = ''
	for y in postsinfo:
		for x in range(0,4):
			posts = posts + re.subn(('<!--INSERT %s\ HERE-->' % y[x]), y[x],
posttemplate)
	return posts

p.s. i apologise for any indentation errors, my client sometimes does
weird stuff. Thanks

	konradkoziol



More information about the Tutor mailing list