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
_______________________________________________
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers

Reply via email to