Python print and types selection
Terry Reedy
tjreedy at udel.edu
Fri Mar 27 20:51:21 EDT 2009
Miles wrote:
> On Fri, Mar 27, 2009 at 6:56 PM, Gabriel Genellina wrote:
>> En Fri, 27 Mar 2009 18:43:16 -0300, <mark.seagoe at gmail.com> 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
>> http://bugs.python.org/issue1742669
>> 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.
Or use Python 3, where the int/long issue is gone ;-)
tjr
More information about the Python-list
mailing list