Object type problem

Mike Fletcher mfletch at tpresence.com
Thu May 11 17:46:44 EDT 2000

Normal response would be to use string formatters...

logstr = '%s: %s\n' % (now, strng )

The problem you're encountering is that you're trying to add None to a
string.  Strings and Nones or strings and numbers are not addable in Python
without an explicit conversion, so, if you want to keep your syntax:

logstr = str( now) + ": " + str( strng) + "\n"


-----Original Message-----
From: Jonathan Donald [mailto:jonathan at ldis.com]
Sent: Thursday, May 11, 2000 4:28 PM
To: python-list at python.org
Subject: Object type problem

Sorry if this is a really dumb question:

I get an odd (to me) error message when trying to do this:

        logstr = now + ": " + strng + "\n"

the error message:

      TypeError: __add__ nor __radd__ defined for these operands 

The facts:

now is a string
strng is _usually_ a string (or None/null, depending on the
circumstances). Maybe something else...?

The error never takes place when strng is a string of one or more

I understand that __add__ and __radd__ are special operator definitions,
and I'm assuming that when this error comes up, strng is not a string,
but another type of object that does not define these operators.

I've tried testing for strng==None, but this doesn't stop the error from
being reported.

I've tried to figure out what class strng belongs to, but I can't seem
to do it.

Can anyone help me?

Many thanks,


More information about the Python-list mailing list