importing same module more than once
Posted
by wallacoloo
on Stack Overflow
See other posts from Stack Overflow
or by wallacoloo
Published on 2010-03-22T01:51:07Z
Indexed on
2010/03/22
1:51 UTC
Read the original article
Hit count: 347
So after a few hours, I discovered the cause of a bug in my application. My app's source is structure like:
main/
__init__.py
folderA/
__init__.py
fileA.py
fileB.py
Really, there are about 50 more files. But that's not the point. In main/__init__.py
, I have this code: from folderA.fileA import *
in folderA/__init__.py
I have this code:
sys.path.append(pathToFolderA)
in folderA/fileB.py
I have this code:
from fileA import *
The problem is that fileA gets imported twice. However, I only want to import it once.
The obvious way to fix this (to me atleast) is to change certain paths from path
to folderA.path
But I feel like Python should not even have this error in the first place. What other workarounds are there that don't require each file to know it's absolute location?
© Stack Overflow or respective owner