I’ve been wondering this for a while: Is it guaranteed to be safe to import a module multiple times? Of course, if the module performs operating systems things like write to files or something, then probably not, but for the majority of simple modules, is it safe to simply perform imports willy-nilly? Is there a convention that governs the global state of a module?
Share
Yes, you can
import moduleas many times as you want in one Python program, no matter what module it is. Every subsequentimportafter the first accesses the cached module instead of re-evaluating it.