现在!我写了一个python项目,我引用了flask。当我写了配置模块,我遇到了一个问题。下面的示例代码不会像我预期的那样工作!在
class ConfigSample:
PREFIX = ''
MAIN_SPLIT = []
MESSAGE_ID = 'message_id'
DEVICE_ID = 'device_id'
HOST = '127.0.0.1'
PORT = 5555
DEBUG = True
ESCAPE_LIST = {}
class Config(dict):
def from_object(self, obj):
for key in dir(obj):
if key.isupper():
self[key] = getattr(obj, key)
class SampleForTestConfigDict:
config = Config()
def __init__(self):
print self.config.get('HOST', 'default host')
if __name__ == '__main__':
p = SampleForTestConfigDict()
#: This config method can be easy load!
p.config.from_object(ConfigSample)
#: There also another config method
p.config['ak'] = 'kkkk'
print p.config
我想在SampleForTestConfigDict init方法中使用config。但是init方法在我用'p赋值之前已经运行过了。config.from_对象'如何解决这个问题?在
目前没有回答
相关问题 更多 >
编程相关推荐