简体   繁体   English

如何从导入的模块导入导入器

[英]how to import the importer from an imported module

What I have is a module data.py that imports another module element.py . 我所拥有的是一个模块data.py ,它导入了另一个模块element.py data.py needs the "element" class stored in element.py while the "element" class in element.py is a subclass of a template "element" class in data.py . data.py需要存储在element.py的“ element”类,而element.py中的“ element”类是data.py模板“ element”类的子类。 and data.py is run first. 并且data.py首先运行。

so: 所以:

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 element.py

import data.py

class element(data.templateElement):
     # class stuff here

So how do I get it to where they can both get the information from each other while not having the template methods each designated to their own file. 因此,如何将它们传递到彼此都可以获取信息而又没有将模板方法分别指定给自己的文件的位置。 or would they have to be? 还是一定要?

How could I set up a template file while still being able to use the custom classes in a different template class on the template file? 如何设置模板文件,同时仍然能够在模板文件上的其他模板类中使用自定义类?

How about: 怎么样:

data.py : data.py

class templateElement(object):
    # all the class stuff here

def somefunction():
    from element import element
    # needs element.py's element object

Meaning, just wait until you have to use it. 意思是,等到您必须使用它。 That way loading data.py would not result in a circular importing. 这样,加载data.py不会导致循环导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM