

Discover more from Daily Dose of Data Science
High-quality insights on Data Science and Python, along with best practices — shared daily.
Get a free 550+ page data science PDF guide and 450+ practice questions notebook.
Over 49,000 subscribers
Continue reading
Prevent Wild Imports With __all__ in Python
Wild imports (𝐟𝐫𝐨𝐦 𝐦𝐨𝐝𝐮𝐥𝐞 𝐢𝐦𝐩𝐨𝐫𝐭 *) are considered a bad programming practice. Yet, here's how you can prevent it if someone irresponsibly does that while using your code.
In your module, you can define the importable functions/classes/variables in __𝐚𝐥𝐥__. As a result, whenever someone will do a wild import, Python will only import the symbols specified here.
This can be also useful to convey what symbols in your module are intended to be private.
Share this post on LinkedIn: Post Link.
Find the code for my tips here: GitHub.
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.