pybites, 9 months ago to python New article: ⚠️Why you should avoid import * in Python 🐍 https://pybit.es/articles/why-you-should-avoid-import-in-python/ Covering: Why modules are great and namespacing explained Why import * is a problem A practical example where a function gets overriden The recommended way to do imports What PEP8 has to say about this Protection workaround, use all to define your module's public interface #python #pythonprogramming #modules #encapsulation #namespacing #zenofpython #bestpractices #pitfalls #imports #dundermethods
New article:
⚠️Why you should avoid import * in Python 🐍 https://pybit.es/articles/why-you-should-avoid-import-in-python/
Covering:
#python #pythonprogramming #modules #encapsulation #namespacing #zenofpython #bestpractices #pitfalls #imports #dundermethods
bbelderbos, 9 months ago to python People newer to Python often get confused by the statement: if name == "main": That's many underscores ("dunders"), right? In essence it lets you put code in your module that ONLY should execute when the module is called directly. So not when you import from it. I explain this further with a practical example in this 3 minute video: https://www.youtube.com/watch?v=ubpFY7_dAW4 #python #pythonprogramming #encapsulation #pythoncoding
People newer to Python often get confused by the statement:
if name == "main":
That's many underscores ("dunders"), right?
In essence it lets you put code in your module that ONLY should execute when the module is called directly. So not when you import from it.
I explain this further with a practical example in this 3 minute video: https://www.youtube.com/watch?v=ubpFY7_dAW4
#python #pythonprogramming #encapsulation #pythoncoding