ImportError: Cannot import name X

前端 未结 16 1220
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 04:33

I have four different files named: main, vector, entity and physics. I will not post all the code, just the imports, because I think that\'s where the error is. (If you want

16条回答
  •  失恋的感觉
    2020-11-22 05:10

    This is a circular dependency. we can solve this problem by using import module or class or function where we needed. if we use this approach, we can fix circular dependency

    A.py

    from B import b2
    def a1():
        print('a1')
        b2()
    

    B.py

    def b1():
       from A import a1
       print('b1')
       a1()
    
    def b2():
       print('b2')
    if __name__ == '__main__':
       b1() 
    

提交回复
热议问题