Create Data Type

Alex Martelli aleax at aleax.it
Tue Feb 4 08:04:45 EST 2003


Gerhard Häring wrote:

> Wezzy <Fabio at est.it> wrote:
>> i didn't think to the simplest solution :  a class without method!
> 
> You might also find the 'Bunch' interesting. It's discussed here:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308
> 
> The definition is very simple:
> 
> class Bunch:
>     def __init__(self, **kwds):
>         self.__dict__.update(kwds)
> 
> Now you can initialize your 'struct' with keyword arguments:
> 
> circle = Bunch(x = 10.0, y = 12.0, radius=5.0)

Also interesting, in (shorl to the appropriate google group search):

http://shorl.com/hypovepateve

I present a custom metaclass to build better versions of Bunch.


Alex





More information about the Python-list mailing list