Is there a way to import a package twice into the same python session under the same name, but in different areas, in a multi-threaded environment?
I would like to import a package and then redefine some of its functions so that it changes its behavior only when used in a specific class.
For example, is it possible to achieve something similar?
import mod
class MyClass:
mod = __import__('mod')
def __init__():
mod.function = new_function
def method():
mod.function()
mod.function()
This may seem strange, but in this case, the user receiving the class will not have to change their code in order to use the improved package.
source
share