我所擁有的是導入另一個模塊element.py
的模塊data.py
。 data.py
需要存儲在element.py
中的「元素」類,而element.py
中的「元素」類是data.py
中的模板「元素」類的子類。並且首先運行data.py
。如何從進口模塊導入導入器
這樣:
data.py
import element.py
class templateElement(object):
# all the class stuff here
class templateOtherObject(object):
# needs element.py's custom element object methods and data
element.py
import data.py
class element(data.templateElement):
# class stuff here
那麼,如何得到它在那裏他們可以得到兩個從每個信息其他雖然沒有模板方法分別指定到自己的文件。或者他們必須是?
如何設置模板文件,同時仍然可以在模板文件的不同模板類中使用自定義類?
您應該避免循環導入。將'templateElement'移出到不同的模塊,並從'data'和'element'中導入。 –
請注意,您需要導入'element',* not *'element.py'。 –
[Python中的循環導入依賴關係]的可能重複(http://stackoverflow.com/questions/1556387/circular-import-dependency-in-python) –