Juanjo Salvador Juanjo Salvador - 6 days ago 5
Python Question

How to add modules in Python?

In Java, we have a main class who calls the classes and methods when needs. I'm trying to build a Python app with the same style: main file and few .py files with extra functionality.

I can import those files using

import <filename without .py>


What if I want to put all those files into a
lib
folder? I want to build a package for PyPI with my app.

Answer
app/
  main.py
  lib/
    __init__.py
    foo.py
    bar.py

#main.py
from lib import foo
foo.SomeClass()