- 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.
- 計(jì)算思維與算法入門(mén)
- .NET之美:.NET關(guān)鍵技術(shù)深入解析
- SQL for Data Analytics
- Python Geospatial Development(Second Edition)
- Java持續(xù)交付
- 編譯系統(tǒng)透視:圖解編譯原理
- Android 應(yīng)用案例開(kāi)發(fā)大全(第3版)
- Unity 5.x By Example
- Learn React with TypeScript 3
- Learning R for Geospatial Analysis
- 從零開(kāi)始學(xué)Linux編程
- Mastering AWS Security
- Machine Learning With Go
- SQL Server 2016 從入門(mén)到實(shí)戰(zhàn)(視頻教學(xué)版)
- Python大規(guī)模機(jī)器學(xué)習(xí)