Import Your Python Package as a Module
A python module is a single python file (.𝗽𝘆). An organized collection of such python files is called a python package.
While developing large projects, it is a good practice to define an __𝗶𝗻𝗶𝘁__.𝗽𝘆 file inside a package.
Consider 𝘁𝗿𝗮𝗶𝗻.𝗽𝘆 has a 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 class and 𝘁𝗲𝘀𝘁.𝗽𝘆 has a 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 class.
Without __𝗶𝗻𝗶𝘁__.𝗽𝘆, one has to explicitly import them from specific python files. As a result, it is redundant to write the two import statements.
With __𝗶𝗻𝗶𝘁__.𝗽𝘆, you can group python files into a single importable module. In other words, it provides a mechanism to treat the whole package as a python module.
This saves you from writing redundant import statements and makes your code cleaner in the calling script.
Read more in this blog: Blog Link.
Read this post on LinkedIn: Post Link.
I like to explore, experiment and write about data science concepts and tools. You can read my articles on Medium. Also, you can connect with me on LinkedIn.