Dynamic class methods misunderstanding

Craig Ringer craig at postnewspapers.com.au
Fri Jan 28 12:09:11 EST 2005


On Fri, 2005-01-28 at 11:17 -0500, Bill Mill wrote:

> Beautiful! thank you very much. Looking into the "new" module in
> python 2.4, that's equivalent to:
> 
> self.m = type(self.__init__)(method, self, Test)
> 
> I didn't know that you could call types to create another type.

Well, a type is essentially a class (in the OOP sense, not the python-
specific classobj sense). You can call a type or class to create an
instance of that class or type. Here, you call the 'instancemethod' type
to create an instance of type 'instancemethod'. Makes sense ... in
hindsight.

-- 
Craig Ringer




More information about the Python-list mailing list