[BangPypers] Multiple return values from a function : Where to draw the line ?
Noufal Ibrahim KV
noufal at nibrahim.net.in
Fri May 23 09:53:04 CEST 2014
On Fri, May 23 2014, Rohit Chormale wrote:
> How is it if you use DataContainer class & set attributes of that class.
> Something like,
>
> class Data(object):
>
> def __init__(self, **kwargs):
> object.__setattr__(self, 'attribs', kwargs)
>
> def __getattr__(self, item):
> if item in self.attribs:
> return self.attribs[item]
> else:
> raise AttributeError
>
> def __setattr__(self, key, value):
> if key in self.attribs:
> self.attribs[key] = value
> else:
> object.__setattr__(self, key, value)
[...]
You could cheat by doing this.
class Data(object):
def __init__(self, **kwargs):
self.__dict__ = kwargs
instead of the above implementation. It's, of course, untested and
unverified.
--
Cordially,
Noufal
http://nibrahim.net.in
More information about the BangPypers
mailing list