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 imported script.
see the docs on subject more. relevant extract:
the
__init__.pyfiles 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__.pycan empty file, can execute initialization code package or set__all__variable, described later.
Comments
Post a Comment