Create a class at run-time

I V ivlenin at gmail.com
Fri Mar 26 16:46:04 EDT 2010


On Fri, 26 Mar 2010 08:54:11 -0700, Michel wrote:

> I want to add a method to a class such that it can be invoked on
> specifics instances.
> You solution works (as well as Patrick's one), thanks ! I still have a
> question though. If I print the type of the self object I get when my
> method is
> called, I get "<class 'test.TestClass'>". I guess this is because the
> method is defined as a class method.
> This is ok in my case, but just out of curiosity, what should I do to
> change this method to an instance method?

It already is an instance method. When you create a TestClass instance, 
the type of that instance is TestClass (the type of TestClass itself is 
"type").



More information about the Python-list mailing list