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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -