Generic utility class for passing data

bonono at gmail.com bonono at gmail.com
Sat Oct 29 07:07:43 CEST 2005


ok, so that is simply a wrapper of a dict and has nothing to do with
parameter passing and it can be used anyway within the receiving
function(or basically anyway I want to say x.key rather than x[key]).

def f(**kwargs):
  x = Bunch(kwargs)
  x.some_key_as_attribute = something




Robert Kern wrote:
> bonono at gmail.com wrote:
> > just curious, since python don't care what object is being passing
> > around and the receiving function has to 'decode' it(be it tuple or
> > dict or whatever). What is the advantage of dummy class ?
>
> The convenience of the attribute notation.
>
> For the record, my favorite variation is as follows:
>
> class Bunch(dict):
>     def __init__(self, *args, **kwds):
>         dict.__init__(self, *args, **kwds)
>         self.__dict__ = self
>
> --
> Robert Kern
> rkern at ucsd.edu
>
> "In the fields of hell where the grass grows high
>  Are the graves of dreams allowed to die."
>   -- Richard Harter




More information about the Python-list mailing list