특정 속성 또는 하위 모듈 (즉, Import)을 지정하지 않고 가져 오기 명령문이 사용되는 경우 두 모듈 모두 성공적으로로드하고 문제없이 서로 액세스 할 수 있습니다.
의 합병증은 순환 수입 내에서 호출 할 때 문제가 발생합니다. 다음 시나리오를 고려하십시오. 모듈 A 모듈 B에서 기호 A 가져 오기는 모듈 B에서 기호를 가져옵니다.이 원형 의존성은 각 모듈이 자체 가져 오기를 완료하기 전에 다른 모듈이 완전히로드되어야하는 상황을 만듭니다. The underlying cause is that the interpreter attempts to recursively import the same module, leading to a stack overflow.
Nonfatal Circular ImportsDespite the aforementioned issues, there exist scenarios where circular imports can coexist harmoniously, as demonstrated in the examples outlined in the original question. These exceptions typically involve combinations of top-level imports, relative imports, and importing specific attributes rather than entire modules.
ConclusionWhile circular imports in Python can be inherently problematic, understanding their nuances and employing the appropriate import strategies can help developers navigate these intricate situations effectively. 이 가이드 라인을 준수함으로써, 원형 수입을 활용하여 함정을 만나지 않고 원하는 기능을 달성 할 수 있습니다.
부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.
Copyright© 2022 湘ICP备2022001581号-3