I have this weird Python import and I can't get it to work with any of the suggestions in other discussions.
I'm currently adding a small script to someone else's module, so I cannot change the file structure or any of the existing code, which makes things difficult.
Here is an example of the python script which contains a bunch of classes:
/path/to/root/directory/aaa/bbb/ccc/utils.py
The current developer imports this as follows:
from aaa.bbb.ccc import utils
utils.SomeClass.someMethod()
All directories in the tree have a __init__.py
file
Now I want to call the module externally as follows:
import sys
sys.path.append('/path/to/root/directory')
from aaa.bbb.ccc import utils
utils.SomeClass.someMethod()
This does NOT work, and gives the the following error:
from aaa.bbb.ccc import utils
ImportError: No module named ccc
However, changing the import a little bit does work:
import sys
sys.path.append('/path/to/root/directory')
from aaa.bbb.ccc.utils import *
SomeClass.someMethod()
I do not understand why the 2nd one works and not the 1st. Again, I cannot change the existing code, so the following 2 statements must work with my sys.path.append and imports:
from aaa.bbb.ccc import utils
utils.SomeClass.someMethod()
I cannot remove the utils
from utils.SomeClass
Does anyone know how I can achieve this?