Dynamic subclassing ?

manatlan manatlan at gmail.com
Sun May 13 04:04:03 EDT 2007


On 12 mai, 18:57, Karlo Lozovina <_karlo_ at _mosor.net> wrote:
> manatlan wrote:
> > I can't find the trick, but i'm pretty sure it's possible in an easy
> > way.
>
> It's somewhat easy, boot looks ugly to me. Maybe someone has a more
> elegant solution:
>
> In [6]: import new
>
> In [13]: class Button:
>     ....:     def buttonFunc(self):
>     ....:         pass
>
> In [14]: class ExtensionClass:
>     ....:     def extendedMethod(self):
>     ....:         pass
>
> In [15]: hybrid = new.instance(Button,
> Button.__dict__.update(ExtensionClass.__dict__))
>
> In [17]: dir(hybrid)
> Out[17]: ['__doc__', '__module__', 'buttonFunc', 'extendedMethod']
>
> Seems to do what you want it to do.
>
> HTH,
> Karlo.

yes, i think it's the only solution ... it's weird
but it seems to be the only one ...
i will try that ...




More information about the Python-list mailing list