![]() ![]() a = module() # import aįor python to be able to work with circular dependencies you must use import x style only. Once the circularly dependent modules are compiled it updates the imported module. Essentially all that happens is that an empty placeholder is created for the module (ie. Python is able to detect circular dependencies and prevent the infinite loop of imports. The reason for this problem is that you asking to access the contents of the module before it is ready - by using from x import y. The problem occurs because in vector you demand that entity be made available for use immediately, and vice versa. It can be solved without any structural modifications to the code. See Why do circular imports seemingly work further up in the call stack but then raise an ImportError further down? for technical details on why and how the problem occurs. See also What happens when using mutual or circular (cyclic) imports in Python? for a general overview of what is allowed and what causes a problem WRT circular imports. I'm assume the error is due to importing entity twice - once in main.py and later in physics.py - but how can I work around the problem? I then run from main.py and I get the following error: Traceback (most recent call last): I have some code spread across multiple files that try to import from each other, as follows: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |