type error on porting outfile.write
Dave Hansen
iddw at hotmail.com
Wed Dec 21 09:52:31 EST 2005
On Tue, 20 Dec 2005 22:11:01 -0500 in comp.lang.python, Eric McCoy
<ctr2sprt at comcast.net> wrote:
>pmiller at gnf.org wrote:
>> I ported my code from the development to
>> application platform, I found a "type error"
>> on a fileout statement:
>
>> outfile.write(object.id +",")
>
>What is the type of object.id? I'm guessing an integer. The exception
>should tell you, e.g.:
>
> TypeError: unsupported operand type(s) for +: 'int' and 'str'
>
>If I'm right, you can do this:
>
> outfile.write("%d," % (object.id))
Or, more generally,
outfile.write("%s, " % object.id)
or even (closer to the original code)
outfile.write(str(object.id)+", ")
Regards,
-=Dave
--
Change is inevitable, progress is not.
More information about the Python-list
mailing list