导入/包含配置Python

时间:2013-05-03 15:34:38

标签: python google-app-engine python-2.7 webapp2

是否可以将config['webapp2_extras.API']等配置存储在其他文件中,然后将其包含在另一个文件中?

伪代码:

# config.py
config['webapp2_extras.API'] = {
  'option' : value,
}

# frontcontroller.py
webapp2.WSGIApplication([
    webapp2.Route('/',handler='MainHandler')
  ], config={{CONFIG_FROM_CONFIG.PY}})

我真的希望能够将我的配置存储在我的前控制器之外的其他地方!谢谢!

2 个答案:

答案 0 :(得分:1)

您是否尝试在frontcontroller.py中导入配置?例如

# config.py
config['webapp2_extras.API'] = {
  'option' : value,
}

# frontcontroller.py
import config

webapp2.WSGIApplication([
    webapp2.Route('/',handler='MainHandler')
  ], config=config)

答案 1 :(得分:0)

尝试将config放在与frontcaller.py相同的文件夹中

# config.py
config['webapp2_extras.API'] = {
  'option' : value,
}

# frontcontroller.py
from . import config

webapp2.WSGIApplication([
    webapp2.Route('/',handler='MainHandler')
  ], config=config.config)