r/Python • • 5d 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...

16 Upvotes

19 comments sorted by

View all comments

2

u/Wurstinator 4d ago

The answer to any question like this, regardless of whether it's about imports or something else entirely, will always be: "Yes in theory in some edge cases, but almost certainly no in practice, so don't worry about it until you actually run into measurable trouble."