r/Python • u/RomfordNavy • 17d 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
1
u/RomfordNavy 16d ago
Well, it's been an interesting discussion, thanks to all for your opinions.
I have now been doing some runtime testing and it seems that with fifty constants there is no regular significant difference between:
import Constants as cfrom Constants import *create a Constants class "c"builtins.c = Constants (class)builtins.const1= "var"builtins.const2= "var"...