Generic utility class for passing data

Alex Martelli aleaxit at yahoo.com
Sat Oct 29 04:50:04 CEST 2005


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