python - What is the purpose of the __init__.py? -
this question has answer here:
- what __init__.py for? 9 answers
when creating python package, told create blank file called init.py. don't understand why need create file. distutils
build script doesn't modify it, 5 builds later it's still blank. it's purpose?
it signal python folder package, not folder. contains initialization code run when package import
ed script.
see the docs on subject more. relevant extract:
the
__init__.py
files required make python treat directories containing packages; done prevent directories common name, suchstring
, unintentionally hiding valid modules occur later on module search path. in simplest case,__init__.py
can empty file, can execute initialization code package or set__all__
variable, described later.
Comments
Post a Comment