[Tutor] Re: cannot concatenate str with tuple obj

Andrei project5 at redrival.net
Thu Oct 23 19:01:43 EDT 2003


Conrad Koziol wrote:

> 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. :) 

You should have posted the traceback, not just the code (the traceback 
tells you a code line number as well). It's harder to guess where the error 
is without that traceback.

> 	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

This is where you get the error? Because the subn docs say this:

subn( pattern, repl, string[, count])
Perform the same operation as sub(), but return a tuple (new_string, 
number_of_subs_made).

Pay attention to what it returns. This means that you're trying to 
concatenate a string (posts) and a tuple (the results of subn).

-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V 
ernq gur yvfg, fb gurer'f ab arrq gb PP.





More information about the Tutor mailing list