Python print and types selection

Miles semanticist at
Sat Mar 28 00:00:38 CET 2009

On Fri, Mar 27, 2009 at 6:56 PM, Gabriel Genellina wrote:
> En Fri, 27 Mar 2009 18:43:16 -0300, <mark.seagoe at> escribió:
>> Python print recognizes the local constant "dog", but it goes and
>> fetches the __int__ type from my object-based class, even though it's
>> value is a long.  Then Python print doesn't expect a long to come back
>> and bombs out.  I don't want to force the main program to cast the
>> long value getting returned.  I know Python print can print a long,
>> but how can I make it select the __long__ instead of the __int__ ?
> This bug was corrected in version 2.6 - see
> If you have to stay with 2.5 I'm afraid any solution would require to modify
> your code:
> -- put long() around those arguments
> -- "%s" % format_hex(val) (where format_hex does the long conversion)
> -- redefine __str__ and use %s

Or make your class a subclass of long.


More information about the Python-list mailing list