Reputation: 7302
This is my file structure:
annotations
Helper.py
annotations.py
test
HelloWorld.py
This is HelloWorld.py
, a simple HelloWorld
class:
from annotations.annotations import annie
class HelloWorld:
@annie.mydecorate
def something():
echo 'Hello World'
And within annotations.py
, I'm just declaring some simple decorators:
from annotations.Helper import Helper
class annie:
@staticmethod
def mydecorate(func):
Helper.prepare()
print func.__name__
Here I get an error saying No such module: Helper
. I guess this is happening when the module HelloWorld
is being loaded, it is loading the annotations module, but the function is being called during the module being loaded at which time the Helper
module is not loaded. I'm not sure how correct I am, but I am just looking for a solution here.
Is the problem something else? Can I import modules like I am doing in a file which declares decorators? Any help would be greatly appreciated.
Regards, rohan
Upvotes: 2
Views: 376
Reputation: 75507
In annotations.py
, try:
import Helper
or (relative imports, Python 2.5 and up)
from . import Helper
Upvotes: 2
Reputation: 14873
Try This:
annotations
Helper.py
annotations.py
__init__.py
HelloWorld.py
Upvotes: 0