Re: MethodType in python 2.2

From: Terry Reedy (tjreedy_at_udel.edu)
Date: 11/10/04


To: python-list@python.org
Date: Tue, 9 Nov 2004 21:10:04 -0500


"George Sakkis" <gsakkis@eden.rutgers.edu> wrote in message
news:Pine.GSO.4.58.0411092019550.25667@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
]



Relevant Pages

  • Re: static methods
    ... An instance method has no meaning to the class itself. ... Note, though, that since the method square() never references ... private int number; ... public Number(int num) ...
    (comp.lang.java.programmer)
  • Re: random number generator help
    ... You are calling an instance method from a static method. ... It will work if you add the keyword "static" to the instance method: ... private static int RandomNumber ... Random random = new Random; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Linked List in Java
    ... > Except for the built-in type(i.e. ... int), all other type objects will ... No. Normal declaration/definitions will allocate memory for any type. ...
    (comp.lang.cpp)