Python package - setup __init__.py to import method direct from submodule

Viewed 16

Let's say we have a Python Project like this:

setup.py
project/
    __init__.py
    subdir/
        __init__.py
        submodule.py

And in submodule.py looks like this:

def my_method():
   return "I am a method"

How can I setup the __init__.py (project/__init__.py and subdir/__init__.py) files that I can import the method "my_method" like this after I installed the package:

from project.subdir import my_method

I do not want to do something like this:

from project.subdir import submodule
submodule.my_method()

Any idea? :-)

0 Answers
Related