what should we use instead of the 'new' module?
robert.kern at gmail.com
Thu Nov 13 04:39:32 CET 2008
> How is this code going to look like in Python 3.0? (it's deprecated
> according to http://docs.python.org/library/new.html#module-new, but
> it does not tell what to use instead)
> method = new.instancemethod(raw_func, None, cls)
> setattr(cls, name, method)
Use the type objects in the types module.
In : import types
In : class A(object):
In : def foo(self, x):
....: print x
In : A.foo = types.MethodType(foo, None, A)
In : a = A()
In : a.foo('See?')
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list