What exactly is the use of __init__.py
? Yes, I know this file makes a directory into an importable package. However, consider the following example:
project/
foo/
__init__.py
a.py
bar/
b.py
If I want to import a
into b
, I have to add following statement:
sys.path.append('/path_to_foo')
import foo.a
This will run successfully with or without __init__.py
. However, if there is not an sys.path.append
statement, a "no module" error will occur, with or without __init__.py
. This makes it seem lik eonly the system path matters, and that __init__.py
does not have any effect.
Why would this import work without __init__.py
?