0

I can import methods

# ~/main/main.py
from my_utils import get_logger, get_driver
...

in other python file inside the same folder.

# ~/main/my_utils.py
def get_logger:
....
def get_driver:
...

I want to know if it is possible to import file in different folder

# ~/main/main.py
from sub.my_utils import get_logger, get_driver # this is ok in eclipse, but has error in command line
...

something like:

# ~/sub/my_utils.py
def get_logger:
....
def get_driver:
...

There is __init__.py file, but I got error in command line, though eclipse is ok.

from sub.my_utils import get_logger, get_driver
ModuleNotFoundError: No module named 'sub'`
EMKAY
  • 355
  • 5
  • 14
mikezang
  • 2,291
  • 7
  • 32
  • 56
  • Also [Importing from sub-folder hierarchy in python](//stackoverflow.com/q/11501870) – Aran-Fey Sep 20 '18 at 06:06
  • add `__init__.py` to each directory you import from, although I would create a directory for the entire program, then make subdirectories for modules, don't make module directories in your home dir and try to import from there as that could be messy. – d_kennetz Sep 20 '18 at 06:08
  • I put file `__init__.py` in sub folder, though it is ok in eclipse, but not in command line! I appended error. – mikezang Sep 20 '18 at 06:23

0 Answers0