[BangPypers] MetaClass in python

Nitin Kumar nitin.nitp at gmail.com
Wed Jan 12 16:43:41 CET 2011


Hi Taj,

On Wed, Jan 12, 2011 at 3:43 PM, Sirtaj Singh Kang <sirtaj at sirtaj.net>wrote:

>
> On 11-Jan-11, at 8:47 PM, Nitin Kumar wrote:
> [snip]
>
>  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


So {} can contain function also for the new class, if then can you give
example for the same. As i need function to class being generated.



> reassign any "method" of the class to a function of your choice as long as
> it takes at least one argument.
>
> -Taj.
>
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>



-- 
Nitin K


More information about the BangPypers mailing list