What happens when using mutual or circular (cyclic) imports?

In Python, what happens when two modules attempt to import each other? More generally, what happens if multiple modules attempt to import in a cycle?


See also What can I do about "ImportError: Cannot import name X" or "AttributeError: ... (most likely due to a circular import)"? for the common problem that may result, and advice on how to rewrite code to avoid such imports. 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.

← Назад к списку