I have a directory that stores all the .py files.
bin/
main.py
user.py # where class User resides
dir.py # where class Dir resides
In python3, __init__.py
is no longer necessary. If the current directory of the console is the directory where the python script is located, everything works fine with
import user
However, this won't work if called from a different directory, which does not contain user.py
.
In that case, use
from . import user
This works even if you want to import the whole file instead of just a class from there.