[Python-ideas] Adding some standalone iterator/sequence functions as methods of the iterator objects

Jan Kaliszewski zuo at chopin.edu.pl
Thu Aug 13 20:32:36 CEST 2009

13-08-2009 Bill Janssen <janssen at parc.com> wrote:

>     a = class(Mixin1, Mixin2, Mixin3)()
>     a.mixin1_method_foo()
>     a.mixin3_method_bar()

Something similar already is possible out of the box:

a = type('a', (Mixin1, Mixin2, Mixin3), {})()

You could also make creating of such objects more compact
by using prepared factory function, e.g.

def makeclass(*base_classes, **kwargs):
     cls_name = kwargs.get('name', 'noname')
     cls_attrs = kwargs.get('attrs', {})
     return type(cls_name, base_classes, cls_attrs)

Then you have exactly what you wanted:

a = makeclass(Mixin1, Mixin2, Mixin3)()

Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>

More information about the Python-ideas mailing list