Re: [BangPypers] Tip: Creating new classes on the fly

2010-07-24 Thread Jeffrey Jose
On Tue, Jul 20, 2010 at 9:56 AM, Roshan Mathews wrote: > I came across this in a blog post just now. > See http://docs.python.org/library/functions.html#type > > >>> class Foo(object): pass > ... > >>> Bar = type('Bar', (object,), dict()) > What you mentioned here is the exact mechanism of a ins

[BangPypers] Tip: Creating new classes on the fly

2010-07-19 Thread Roshan Mathews
I came across this in a blog post just now. See http://docs.python.org/library/functions.html#type >>> class Foo(object): pass ... >>> Bar = type('Bar', (object,), dict()) >>> f = Foo(); b = Bar() >>> type(f), type(b) (, ) Also see http://docs.python.org/library/collections.html#namedtuple-facto