Python 在声明decorators的文件中导入模块

Python 在声明decorators的文件中导入模块,python,decorator,Python,Decorator,这是我的文件结构: annotations Helper.py annotations.py test HelloWorld.py 这是HelloWorld.py,一个简单的HelloWorld类: from annotations.annotations import annie class HelloWorld: @annie.mydecorate def something(): echo 'Hello World' 在anno

这是我的文件结构:

annotations
    Helper.py
    annotations.py
test
    HelloWorld.py
这是
HelloWorld.py
,一个简单的
HelloWorld
类:

from annotations.annotations import annie

class HelloWorld:
    @annie.mydecorate
    def something():
        echo 'Hello World'
annotations.py
中,我只声明了一些简单的装饰器:

from annotations.Helper import Helper

class annie:
    @staticmethod
    def mydecorate(func):
        Helper.prepare()
        print func.__name__
这里我得到一个错误,说
没有这样的模块:Helper
。我猜这是在加载模块
HelloWorld
时发生的,它正在加载annotations模块,但是在加载模块的过程中调用了函数,此时没有加载
Helper
模块。我不确定我有多正确,但我只是在这里寻找一个解决方案

这个问题是其他问题吗?我可以像在声明decorators的文件中那样导入模块吗?任何帮助都将不胜感激

问候,, rohan

试试这个:

annotations
    Helper.py
    annotations.py
    __init__.py
HelloWorld.py

annotations.py
中,尝试:

import Helper
或(相对导入,Python 2.5及更高版本)


你的诊断不正确。添加更多细节。这正是我做错的地方。我假设导入发生在导入它的文件的根目录中。。但是男孩,那是错的。非常感谢你。
from . import Helper