Oops, sorry for the spam. I didn't see that there were already answers
in the rest of the thread. :-(

On Feb 13, 2008 9:25 PM, Jeffrey Yasskin <[EMAIL PROTECTED]> wrote:
> On Feb 13, 2008 1:42 PM, Eric Smith <[EMAIL PROTECTED]> wrote:
> > Guido van Rossum wrote:
> > >> Much to my surprise, this already works:
> > >>
> > >>  >>> format(oldstyle(), '+^50s')
> > >> '+++++<__main__.oldstyle instance at 0x3d91f8>+++++'
> > >>  >>>
> > >>
> > >> So I guess it's a moot point.  I'm using the same code as I use in 3.0,
> > >> where I call:
> > >>    meth = _PyType_Lookup(Py_TYPE(value), format_str);
> > >> where format_str is "__format__" interned.  And I'm getting a value back
> > >> for old style classes.
> > >>
> > >> Eric.
> > >
> > > But now try overriding __format__().  The 3.0 code uses
> > > _PyType_Lookup() which is not traversing the class dicts for classic
> > > classes, so it won't find __format__ overrides.
> > >
> >
> > Okay, I see and understand that issue.  But looking at len or getattr, I
> > don't see how to generalize it to __format__.  __len__ and __getattr__
> > have special support in the classes, with cl_getattr, tp_getattr, etc.
> >
> > I hate to be dense, but could you point me to some code that does
> > something similar but looks up the method by name?
>
> I'm not sure if it'll be exactly analogous, but you might look at
> __trunc__ and math.trunc for inspiration.
>
> --
> Namasté,
> Jeffrey Yasskin
> http://jeffrey.yasskin.info/
>



-- 
Namasté,
Jeffrey Yasskin
http://jeffrey.yasskin.info/
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to