Python 覆盖导入模块中导入的类

Python 覆盖导入模块中导入的类,python,python-3.x,Python,Python 3.x,我有一个模块,它使用从其他地方导入的类。我想将导入模块使用的类更改为我在程序中定义的类。举例说明: a.py模块 class kdtree: def get(self): return 5 from a import kdtree def execute(): tree = kdtree() print(tree.get()) b.py模块 class kdtree: def get(self): return 5 from

我有一个模块,它使用从其他地方导入的类。我想将导入模块使用的类更改为我在程序中定义的类。举例说明:

a.py模块

class kdtree:
    def get(self):
        return 5
from a import kdtree
def execute():
    tree = kdtree()
    print(tree.get())
b.py模块

class kdtree:
    def get(self):
        return 5
from a import kdtree
def execute():
    tree = kdtree()
    print(tree.get())
c.py模块将被执行

import b
b.execute()

我不想修改a.py或b.py,但我想修改
kdtree
以在c.py中使用我自己的
kdtree
类。这在python中可能吗?

您可以在
c.py
中使用不同的属性覆盖模块
b
kdtree
属性:

# c.py
import b
class kdtree:
    def get(self):
        return 10
b.kdtree = kdtree
b.execute()

所有东西都在你的文件夹里吗?如果没有,请显示文件夹结构。不,它们都在不同的文件夹中