我所拥有的是一个模块data.py,它导入另一个模块element.py。data.py需要存储在element.py中的"element“类,而element.py中的"element”类是data.py中模板"element“类的子类。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 dataelement.py
import data.py
class element(data.templateElement):
# class stuff here那么,我如何才能让它们彼此获取信息,同时又不让模板方法各自指定到自己的文件中。或者他们必须这样做?
如何在仍然能够在模板文件上的其他模板类中使用自定义类的情况下设置模板文件?
发布于 2013-08-26 22:22:55
不如:
data.py
class templateElement(object):
# all the class stuff here
def somefunction():
from element import element
# needs element.py's element object意思是,等到你必须使用它。这样,加载data.py不会导致循环导入。
https://stackoverflow.com/questions/18453821
复制相似问题