python - What is the purpose of the __init__.py? -


this question has answer here:

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__.py files required make python treat directories containing packages; done prevent directories common name, such string, 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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -