Modifying builtin type behaviour
Andrew Bennetts
andrew-pythonlist at puzzling.org
Wed Feb 18 19:10:38 EST 2004
On Tue, Feb 17, 2004 at 05:17:49PM +0100, Gerrit wrote:
> Jean-S?bastien Bolduc wrote:
> > I'm afraid this is a silly question, to which I know the answer
> > already. But let me ask anyway...
> >
> > In Python, is there a way to modify a builtin type's methods? for
> > instance, modifying int.__add__ to behave as multiplication, I would
> > obtain 2+5 == 10. I emphasize that I don't want to modify the Python
> > source, but change the types behaviour _from within Python_.
>
> Why?
Yes, why? There's a decent chance you can do what you want without
modifying builtin types.
> > Help would be appreciated!
>
> I'm almost sure it isn't possible...
Anything is possible, given sufficient quantities of evil:
http://www.intarweb.us:8080/evil/intrinsics.c
http://www.intarweb.us:8080/evil/intrinsics_example.py
http://www.intarweb.us:8080/PyCon/intrinsics-lightning-0.xhtml
-Andrew.
More information about the Python-list
mailing list