[BangPypers] MetaClass in python

Sirtaj Singh Kang sirtaj at sirtaj.net
Wed Jan 12 11:13:59 CET 2011

On 11-Jan-11, at 8:47 PM, Nitin Kumar wrote:
> So i do know who to create a class and its function dynamically at
> runtime???

You can dynamically create a class like this:

NewClass = type('NewClass', (object,), {})

where 'NewClass' is the name of your class, (object,) is any tuple of  
superclasses and {} will be the __dict__ of the new class. As steve  
mentioned earlier, you can reassign any "method" of the class to a  
function of your choice as long as it takes at least one argument.


More information about the BangPypers mailing list