circular-dependency

Circular dependency in Python

妖精的绣舞 提交于 2019-11-26 00:33:59
问题 I have two files, node.py and path.py , which define two classes, Node and Path , respectively. Up to today, the definition for Path referenced the Node object, and therefore I had done from node.py import * in the path.py file. However, as of today I created a new method for Node that references the Path object. I had problems when trying to import path.py : I tried it, and when the program ran and called the Path method that uses Node , an exception rose about Node not being defined. What

Circular (or cyclic) imports in Python

大城市里の小女人 提交于 2019-11-25 23:56:40
问题 What will happen if two modules import each other? To generalize the problem, what about the cyclic imports in Python? 回答1: There was a really good discussion on this over at comp.lang.python last year. It answers your question pretty thoroughly. Imports are pretty straightforward really. Just remember the following: 'import' and 'from xxx import yyy' are executable statements. They execute when the running program reaches that line. If a module is not in sys.modules, then an import creates

Python circular importing?

↘锁芯ラ 提交于 2019-11-25 22:46:20
问题 So i\'m getting this error Traceback (most recent call last): File \"/Users/alex/dev/runswift/utils/sim2014/simulator.py\", line 3, in <module> from world import World File \"/Users/alex/dev/runswift/utils/sim2014/world.py\", line 2, in <module> from entities.field import Field File \"/Users/alex/dev/runswift/utils/sim2014/entities/field.py\", line 2, in <module> from entities.goal import Goal File \"/Users/alex/dev/runswift/utils/sim2014/entities/goal.py\", line 2, in <module> from entities