Python print and types selection

mark.seagoe at gmail.com mark.seagoe at gmail.com
Sat Mar 28 03:49:39 CET 2009


On Mar 27, 7:48 pm, mark.sea... at gmail.com wrote:
> On Mar 27, 4:00 pm, Miles <semantic... at gmail.com> wrote:
>
>
>
>
>
> > On Fri, Mar 27, 2009 at 6:56 PM, Gabriel Genellina wrote:
> > > En Fri, 27 Mar 2009 18:43:16 -0300, <mark.sea... 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.
>
> > -Miles- Hide quoted text -
>
> > - Show quoted text -
>
> Absolute genius.  Wish I had thought of that.  Thanks to both of you.- Hide quoted text -
>
> - Show quoted text -

I mean all three of you.  :)




More information about the Python-list mailing list