Str and instance concatanation error

Hans Nowak wurmy at earthlink.net
Mon Nov 4 18:32:47 EST 2002


Newt wrote:

>   File "D:\py_stuff\globals.py", line 96, in save_char
>     file.write('<creator>' + self.creator + '</creator>')
> TypeError: cannot concatenate 'str' and 'instance' objects

The error says it all: '<creator>' and '</creator>' are strings, self.creator 
is not. They cannot be concatenated. Use something like str(self.creator) if 
possible. Or, in self.creator's class, define __add__ and __radd__ methods that 
allow concatenating of strings.

HTH,

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/
Kaa:: http://www.awaretek.com/nowak/kaa.html




More information about the Python-list mailing list