You can use namedtuple. from collections import namedtuple Person = namedtuple('Person', ['foo', 'bar', 'baz']) p = Person(foo='foo', bar='bar', baz='baz')
print p.foo 'foo' On Fri, May 23, 2014 at 1:23 PM, Noufal Ibrahim KV <nou...@nibrahim.net.in>wrote: > 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 > -- *Thanks & Regardskracekumar"Talk is cheap, show me the code" -- Linus Torvaldshttp://kracekumar.com <http://kracekumar.com>* _______________________________________________ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers