How to Deal with Redundant/Repeated Imports in Python Modules? How to Deal with Redundant/Repeated Imports in Python Modules? python-3.x python-3.x

How to Deal with Redundant/Repeated Imports in Python Modules?


You don't have to do anything. Python import system uses a cache (in the sys.modules dictionary) to prevent a module from being imported twice. Calling import with the same name anywhere in your code will yield the same module object from the first time, thus making module objects kind of "singletons".