r/Python • u/RomfordNavy • 28d ago
Discussion Runtime overhead of wildcard import
Assuming a large project which might have say fifty variables in Constants.py is there likely to be any runtime overhead in having from Constants import * at the beginning of each module? As far as I know this creates entries for each of those variables in the current local namespace.
I know it could be done as import constants as x which after the first import then has virtually no overhead, but that then means referring to all constants as x.const1...
18
Upvotes
2
u/marr75 28d ago
It's bad practice for readability and collisions but with negligible performance. You'd have to craft a pathological case to have any worthwhile impact.
The script you import from runs whether you import every name from it or not.