0

I have a file layout like this:
settings/
----__init__.py
----common.py
----configs/
--------constants1.py
--------constants2.py
----debug/
--------include1&2.py
--------include1.py
--------include2.py

and when I import settings.debug.include1, I would like the settings file to execute/import common.py then override the settings in common.py with the proper constants file. Problem is, this isn't happening. Is there a way to accomplish my goals in this fashion?

4

2 に答える 2

2

いいえ。from ... import *またはexecfile()を使用しsettings/__init__.pyて、適切なファイルをロードします。

于 2012-06-26T07:21:28.200 に答える
0

ほとんどのコメントがすでに示唆しているようfrom module import *に、適切なファイルで使用できます。それらは次のように見えるかもしれません..

--

# settings/common.py

DEBUG = False

--

# settings/configs/constants1.py

CONSTANT_1 = 'One'

--

# settings/configs/constants2.py

CONSTANT_2 = 'Two'

--

# settings/debug/include1.py

from settings.common import *
from settings.configs.constants1 import *

# Override settings here
DEBUG = True
CONSTANT_1 = '1'

--

# settings/debug/include2.py

from settings.common import *
from settings.configs.constants2 import *

# Override settings here
DEBUG = True
CONSTANT_2 = '2'

そして、2つのデバッグの組み合わせには含まれています

# settings/debug/include1and2.py

from settings.debug.include1 import *
from settings.debug.include2 import *

また

# settings/debug/include1and2.py

from settings.common import *
from settings.configs.constants1 import *
from settings.configs.constants2 import *

# Override settings here
于 2012-06-26T12:38:10.060 に答える