I faced this problem while i was expirementing with my project.My project is designed so it has multipule submoudles.
Now each submodule needs a position of an the same item on the screen,which is random each time the program ran.I thought it was a good idea to check once where is the position of the item (It does not change in runtime) , and let all modules access the position.(Since checking the position takes a long time)
This is what i did:
position = get_pos()
Config.pos = position
pos = None
from Packages.Package_A import a
Config.Position = (124, 586)
if __name__ == '__main__':
Position = None
from mainPackage import Config
None -> from Package_A
(124, 586) -> from b.py
The problem is in a.py:
from mainPackage import Config. You did an absolute import from a package and ended up importing
Config twice. Python only imports a module once but in your case you used two different names (
Config in some files,
mainPackage.Config in others) which confused python and it imported the module twice - once by a package relative import and once by an absolute import. Add
print "Importing Config" to Config.py and you will see it printed twice.
Just change a.py to
import Config and all will be well.