How do I structure Python code into modules/packages?
Question: Assume I have this barebones structure:

    
    
    project/
      main.py
      providers/
        __init.py__
        acme1.py
        acme2.py
        acme3.py
        acme4.py
        acme5.py
        acme6.py
    

Assume that `main.py` contains (partial):

    
    
    if complexcondition():
      print providers.acme5.get()
    

Where `__init__.py` is empty and `acme*.py` contain (partial):

    
    
    def get():
      value=complexcalculation()
      return value
    

How do I change these files to work?

Note: If the answer is "import acme1", "import acme2", and so on in
`__init__.py`, is there a way to accomplish that without listing them all by
hand?


Answer: hey! two years later but... maybe could be helpfull to some one

make your **providers/__init__.py** like that:

    
    
    import os
    import glob
    
    module_path = os.path.dirname(__file__)
    files = glob.glob(os.path.join(module_path, 'acme*.py'))
    __all__ = [os.path.basename(f)[:-3] for f in files]
    

you don't have to change it later if add or remove any **providers/acme*.py**

then use `from providers import *` in **main.py**

