From: Paul Brossier Date: Sun, 14 Apr 2013 22:13:18 +0000 (-0500) Subject: timeside/analyzer/core.py: trick to access result['foo'] as result.foo X-Git-Tag: 0.5.0~115^2~38 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5523ddbb036cf9e5ebe1d6def94055fc8de3ef21;p=timeside.git timeside/analyzer/core.py: trick to access result['foo'] as result.foo --- diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index 5453a1b..d8f1699 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -36,6 +36,12 @@ class AnalyzerResult(dict): if type(value) not in [list, str, float, int]: raise TypeError, 'AnalyzerResult only accepts types [list, str, float, int], not %s' % type(value) if name == 'value': self['value'] = value + return super(AnalyzerResult, self).__setattr__(name, value) + + def __getattr__(self, name): + if name in ['id', 'name', 'unit', 'value']: + return self[name] + return super(AnalyzerResult, self).__getattr__(name) class AnalyzerResultContainer(object):