[colug-432] python’s __init__.py

Rick Hornsby richardjhornsby at gmail.com
Wed Aug 28 22:42:19 EDT 2019


I more or less get most of python’s major features. I think. One thing I’m
not able to understand however, is __init__.py. I understand that:

* you’re supposed to use it when you organize your code into directories,
and this namespaces/groups the directory contents into a module
* its contents is executed (at some point?)

Most of what I can find about it mentions creating __init__.py as an empty
file and why, but then doesn’t go on to suggest what the contents should
be. I’ve been trying to use it as a way to organize import statements, but
to be honest I can’t make sense of why it works sometimes and not others,
why it might work in one sibling directory, but not another, and so on.

I have this impression that the contents of the file are supposed to be a
hint or suggestion or automated way for other things to say ‘import
<module_dir>` and dir’s __init.py__ will in turn import local modules on
behalf of the caller?

What is __init.py__ supposed to contain? Other than being an empty file,
does it serve any purpose, provide anything for your code?

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.colug.net/pipermail/colug-432/attachments/20190828/ce8dd62f/attachment.html 


More information about the colug-432 mailing list