Reputation: 11468
Just for my knowledge, how does python, especially wxpython reacts to multiple imports? If I import wx in multiple files, how does it handle that when called the main frame? Does it slows the speed or it firstly checks whether it is already been imported or not?
Upvotes: 2
Views: 121
Reputation: 798744
Only the first import executes the file. Subsequent imports copy the reference from sys.modules.
Upvotes: 3
Reputation: 69051
When Python imports a file, it keps track of it by storing it in sys.modules
. So whenever Python is importing a file it checks there first and, if it finds it there, returns that instead; if it is not there, it imports it, adds it to sys.modules
, and then returns it.
Upvotes: 5