Overriding module's class
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Thu Dec 3 17:20:56 EST 2009
Pavel Skvazh a écrit :
> Is it possible to override a class in the module or the module itself
> that is imported across the project to add new methods to it?
>
> For example I've got
>
> module 'a' with class A
>
> from a import A
>
> but I don't want to add a method to that A class not just in this
> unit, but across the project, so everywhere I'll import class A - it
> would be a modified one.
>
Google for "monkey patch".
FWIW, what turns a function into a method is not the fact that it has
been defined with a class statement, but the fact that it's an attribute
of a class object. Where the function is defined is totally irrelevant.
More information about the Python-list
mailing list