Overriding module's class

  • Thread starter Bruno Desthuilliers
  • Start date
B

Bruno Desthuilliers

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.
 
P

Pavel Skvazh

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.

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top