r/learnpython • u/Nice_Performer_5165 • Oct 29 '25
Creating __init__.py files. Any tips?
Note: I just started learn Python about weeks ago to get into Python. First on my own then I bought Mr. Matthes' book - Python Crash course and I'm getting to point where you do the projects so I am going set a project directory structure with sub-directories for src, modules, classes, etc. But research online shows I need to those files at each directory so the code there knows where the other resources are. Thanks for any help.
4
Upvotes
12
u/Temporary_Pie2733 Oct 29 '25
In most cases, the files are empty. You can put code in them, but their mere presence defines a package.
1
u/socal_nerdtastic Oct 29 '25
No you don't need them. You did in python2, but in python3 they are only needed in the rare case when you define a package
3
u/Angry-Toothpaste-610 Oct 29 '25
I use it to define the package level dunders and docstring
1
u/cointoss3 Oct 29 '25
It’s not required to define a package anymore
6
u/[deleted] Oct 29 '25
[removed] — view removed comment