Play with classes
David M. Cook
davecook at nowhere.net
Thu Feb 26 12:33:11 EST 2004
In article <cth4qte878u.fsf at lcpxdf.wm.lc.ehu.es>, Zunbeltz Izaola wrote:
> Supose the user whant to combine ModeA with TypeB and SubtypeB, so I need
> something like
>
> class UserClass(ModeA, TypeB, SubtypeB):
You can use the type builtin (2.2 and above) to create a class type
dynamically. Syntax is
type(name_string, bases_tuple, methods_dict)
For example:
In [68]: foo = type('Foo', (object,), {})
In [69]: foo.mro()
Out[69]: [<class '__main__.Foo'>, <type 'object'>]
Dave Cook
More information about the Python-list
mailing list