Using many names from a #Python module?
-
Using many names from a #Python module? Import them all:
from MODNAME import *
Wait: This is usually a TERRIBLE idea!
• Potential namespace collisions
• Less readable code
• Module upgrades affect globals in your programI know, it's tempting — but don't!

-
Using many names from a #Python module? Import them all:
from MODNAME import *
Wait: This is usually a TERRIBLE idea!
• Potential namespace collisions
• Less readable code
• Module upgrades affect globals in your programI know, it's tempting — but don't!

It's also a violation of the Zen of Python - "namespaces are one honking great idea -- let's do more of those"!
I'd also add that sometimes you want to do this within your own packages - like keeping all the magic constants in a sub-module, but you don't want to have to refer to them as `constants.foo` all through the rest of the code. In this case, use the `__all__` definition in constants.py to explicitly export only the names you want used this way.
-
R relay@relay.publicsquare.global shared this topic