I've just read an article that supposedly introduced me to a new concept: Up to now I was sure that python packages (i.e directories with an __init__.py file) behave exactly the same as java packages, that is - little namespaces to help arrange the code (minus java's "package" scoping).
But, according to this link:
A Short Digression Into Multi-File Modules, if I put all my files in the same "package":
the entire collection of files is presented to other Python code as a single module — as if all the functions and classes were in a single .py
So now I thought that my whole understanding of the python "package" thing was wrong. Moreover - it's entirely not a package, rather a "multifile module" as the author refers to it.
So, from what I understood, no matter to how many files I divide my funcs and classes inside a package, from the outside that package should appear as though I took all the code from all the files inside the package and put it in one big file with the same name as the package instead, i.e as one module.
e.g, if I have the following file structure:
/base
/animals
/__init__.py
/dog.py
and in dog.py:
def bark():
print "woof"
it should be exactly the same as having:
/base
/animals.py
and in animals.py:
def bark():
print 'woof'
thus, this next piece of code should run fine on both cases:
from base import animals
animals.bark()
This of course yields in the first case:
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'module' object has no attribute 'bark'
What am I