I have a directory that contains several .py files/modules. In that directory, I put __init__.py
within with an intent to make it a package. What I would like to have is, when I import the directory, I would access all the methods from individual modules without specifying each module name inside __init__.py
. This means, when I would add a new module, __init__.py
would pick it up and I am free off manual update of that module name inside of __init__.py
. Here is an example to show what I want:
/my_package/
module1.py
module2.py
..........
..........
moduleN.py
Now,
within module1.py
, I have def add(n,m):
within module2.py
, I have def sub(n,m):
etc. etc.
Now, suppose in Jupyter lab, I import like this,
import my_package as mpgk
then I would like to access mpkg.add
, mpkg.sub
What do I need to do inside __init__.py
to make sure the methods from individual modules from that directory are loaded?