[Python-Dev] Adding __format__ to classic classes

Eric Smith eric+python-dev at trueblade.com
Thu Feb 14 12:41:58 CET 2008


Guido van Rossum wrote:
> Try this:
> 
> if (PyInstance_Check(obj)) {
>   bound_method = PyObject_GetAttr(obj,  str__format__);
>   if (!bound_method)
>   return NULL;
>   <call it passing only the format string>
>   Py_DECREF(bound_method);
>   return <whatever the call returned>
> }
> else {
>   do it the py3k way;
> }

Yes!  I had converged on something similar.  Also, in the !bound_method 
branch, I convert using str() or unicode() to get the same behavior as 
object.__format__.

I have one more question, which I'll start in another thread.

Eric.


More information about the Python-Dev mailing list