循环导入

# 循环导入: 大型的python项目中,需要很多python文件,由于架构不当,可能会出现模块之间的相互导入
A: 模块
    def test():
        f()
B: 模块
    def f():
        test()

# 避免产生循环导入:
    # 1. 重新架构
    # 2. 将导入的语句放到函数里面
    # 3. 把导入语句放到模块的最后

示范

A模块:
    # from B import task1
    def func():
        print("-----循环导入2里面的func---1--")    
        from B import task1
        task1()
        print("-----循环导入2里面的func---2--")

B模块:
    from A import func

    def task1():
        print("----task1----")

    def task2():
        print("-----task2------")
        func()

    if __name__ == '__main__':
        # 调用task1
        task1()
        task2()

python 的循环引用 python模块循环引用_python