And you cannot use foo.bar.baz because this does not exists because the module is not yet appended to foo.bar;
$ cat foo/bar/__init__.py
import foo.bar.baz
baz.test()
foo.bar.baz.test()
$ python
>>> import foo
TEST OK
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "./foo/__init__.py", line 1, in <module>
import foo.bar
File "./foo/bar/__init__.py", line 4, in <module>
foo.bar.baz.test()
AttributeError: 'module' object has no attribute 'bar'
With the first line i can access the function, the other one not!
And you cannot use foo.bar.baz because this does not exists because the module is not yet appended to foo.bar;
$ cat foo/bar/__init__.py
import foo.bar.baz
baz.test()
foo.bar.baz.test()
$ python __init_ _.py", line 1, in <module> bar/__init_ _.py", line 4, in <module> bar.baz. test()
>>> import foo
TEST OK
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "./foo/
import foo.bar
File "./foo/
foo.
AttributeError: 'module' object has no attribute 'bar'
With the first line i can access the function, the other one not!