Generic utility class for passing data
bonono at gmail.com
bonono at gmail.com
Sat Oct 29 00:38:40 EDT 2005
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 ?
Alex Martelli wrote:
> Gordon Airporte <JHoover at fbi.gov> wrote:
>
> > I'm wondering if this is might be bad practice. Sometimes when I need to
>
> I hope not, 'cuz I suggested that years ago on the Cookbook (under the
> name of Bunch) with several successive refinements.
>
> > class Dummy:
> > pass
> >
> > Then when I need to pass some related data, Python lets me do this:
> >
> > prefill = Dummy()
> > prefill.foreground = 'blue' #"foreground" is made up on the fly
> > prefill.background = 'red'
> > prefill.pattern = mypattern
> > return prefill
>
> Sure, but you can do even better:
>
> class Dummy(object):
> def __init__(self, **kwds): self.__dict__ = kwds
>
> prefill = Dummy(foreground='blue', background='red', pattern=mypattern)
> return prefill
>
>
> Alex
More information about the Python-list
mailing list