It is a very open question, but I would say your problem is that you are missing the concept of package.
A package is a folder that contains modules, and other packages, allowing for nesting as much as you want. For Python to identify a folder as a package, it has to contain an __init__.py
file (for the moment, just an empty file with that name is enough).
In python a module is a .py
file. I would recommend you not to use that name for folders (aka packages).
Like this, you can create arbitrary structures. For instance, taking your example:
main.py
vendor/
__init__.py
mymodule/
__init__.py
mysubmodule/
__init__.py
any_class.py
Then you define your AnyClass
in any_class.py
. After that you can import from main.py
this way:
from vendor.mymodule.mysubmodule.any_class import AnyClass
Bear in mind that you dont have to import explicitly the class. You can import the module (== python file), the package or whatever your want. Following examples are perfectly valid, although less common.
import vendor
my_obj = vendor.mymodule.mysubmodule.any_class.AnyClass()
from vendor import mymodule
my_obj = mymodule.mysubmodule.any_class.AnyClass()
...
from vendor.mymodule.mysubmodule import any_class
my_obj = any_class.AnyClass()
And another thing to keep in mind is, in python you are not forced to have one class per file like in java. You are free to have more, and if they are tightly related, very often makes sense to have them all in the same module.