Python - how can I override the functionality of a class before it's imported by a different module? -
I have a class that is being imported into module_x
, but first I I want to override one of the class methods to dynamically add a specific feature ( module_x
.
Neither EndeDog nor Andrew's answers answer fully to your question, but they The most important tools are given to be able to solve the problem (both are +1). I am using one of their suggestions in my answer:
You will need 3 files: < / P>
File 1: myClass.py
Category C: def func (auto): #do something
File 2: importclub < / H3> mycolass import defineFunc (): A = C () FEF = Lambda: "I like pie" return A if __name__ == "importer": A = changefun ()
file3: module_x.py
came Import from print * print ()
The output of module_x is "I like"
Hope this
Comments
Post a Comment