python 模块避免循环导入的例子

python 模块避免循环导入的例子
当两个不同的python module要相互导入模块时,应避免循环导入:
from Acquisition import aq_inner, aq_parent
from zope.schema.interfaces import IContextSourceBinder
from zope.schema.vocabulary import SimpleVocabulary

...


@grok.provider(IContextSourceBinder)
def possibleTracks(context):
    
    # we put the import here to avoid a circular import
    from example.conference.program import IProgram
    while context is not None and not IProgram.providedBy(context):
        context = aq_parent(aq_inner(context))
    
    values = []
    if context is not None and context.tracks:
        values = context.tracks
    
    return SimpleVocabulary.fromValues(values)
模块循环导入的详细解释:http://bokee.sinaapp.com/?p=194


设置