- Daniel Arbuckle's Mastering Python
- Daniel Arbuckle
- 164字
- 2021-07-02 21:09:39
Resolving attribute errors raised due to cyclic dependencies
There are two common ways to address the attribute error. The first one is usually considered the best. This method is to break the cycle by taking some of the code from one of the modules and moving it into a third module, which both the other modules can import without causing a cycle. In the following example, if we move the A class into its own module, there would be no cycle and all would be well:

The other way to address this problem is to move the import statement that causes the cycle, as shown in the following screenshot:

If we move the import statement down, as shown in the preceding example, until it's below all the variable definitions that are needed by the other modules in this cycle, the module will be initialized enough when it's imported by the other modules. Python will still come back and finish the initialization later.
- LabVIEW 2018 虛擬儀器程序設(shè)計
- OpenCV 3和Qt5計算機視覺應(yīng)用開發(fā)
- 青少年信息學競賽
- Raspberry Pi Home Automation with Arduino(Second Edition)
- Android驅(qū)動開發(fā)權(quán)威指南
- Scala編程(第5版)
- Learning iOS Security
- 從零開始學Python大數(shù)據(jù)與量化交易
- 3D Printing Designs:The Sun Puzzle
- PHP 7 Programming Blueprints
- C++標準庫(第2版)
- 深入理解TypeScript
- Java核心技術(shù)·卷Ⅱ:高級特性(原書第10版)
- C#灰帽子:設(shè)計安全測試工具
- IBM DB2 9.7 Advanced Administration Cookbook