I have following structure:
utils_dir has generator.py file which has 3 defs.
I have test.py in inline_dir. And I am trying to use defs from generator.py in test.py.
inline_dir and utils_dir are in different folders.
How can I achieve it to use defs?
Tried with creating
from utils import generator
│ ├── dir_aa
│ └──----- main.py [Want to use a and b from generator.py]
|___ def a
|___ def b
It sounds like you're trying to execute a .py file in a subdirectory.
Assuming the following directory structure:
. ├── inline │ ├── __init__.py │ └── main.py └── utils ├── __init__.py └── generator.py
main.py containing a simple import like (the function
a() being defined in
from utils.generator import a if __name__ == '__main__': a()
generator.py would look something like this:
def a(): print "hi there"
You won't be able to run your program using
python inline/main.py because this will set the module search path to
If you want to execute a file in a subdirectory while importing from your project-level, you could do the following:
PYTHONPATH=. python inline/main.py
UPDATE: Added example