MethodType in python 2.2

Terry Reedy tjreedy at udel.edu
Tue Nov 9 21:10:04 EST 2004


"George Sakkis" <gsakkis at eden.rutgers.edu> wrote in message 
news:Pine.GSO.4.58.0411092019550.25667 at er3.rutgers.edu...
> Python 2.2.2 (#1, Jun 25 2003, 18:52:43)
> [GCC 3.3 (SuSE Linux)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import types
>>>> class X:
> ...        def f(self,attr): return getattr(self,attr)
> ...        g = types.MethodType(f,None)
> ...
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>  File "<stdin>", line 3, in X
> TypeError: cannot create 'instance method' instances

In 2.2, *some* type objects, like int, were turned into callable 
contructors as part of the introduction of new-type classes.

> The same code under 2.4 (and I believe 2.3) runs fine.

When the experiment proved to be a success, additional type objects were 
converted.

> Is it possible to get around this in 2.2 ? Thanks in advance,

Perhaps the new module.  Don't know for sure.

Terry J. Reedy
] 






More information about the Python-list mailing list