python - cannot find name in imported module -
my directory structure following:
a/ - b/ - __init__.py - settings.py - mymain.py - settings.py
a/settings.py
#the common names es_hosts = ["localhost"]
b/settings.py:
from a.settings import * #the names specific b.settings
b/main.py
import settings print settings.es_hosts
python tells me
attributeerror: 'module' object has no attribute 'es_hosts'
could tell me how debug problem?
i don't think path work, going out of scope of pythons search. a.settings
level above b.settings
, won't looked @ (python
doesn't search level - , calling mymain.py
, starting point within b
) - either move file has different name in same scope (so under either b
or a
, instead of different nesting levels).
or change python path using sys.path.append(path_to_module)
.
an alternative split a
, b
separate non-nested folders on same level, , have mymain.py
above them, so:
my_proj/ - mymain.py - a/ - __init__.py - settings.py - b/ - __init__.py - settings.py
and have mymain.py
use
import b.settings settings
Comments
Post a Comment