Cool object trick
steven.bethard at gmail.com
Mon Dec 13 05:25:27 CET 2004
> Normally I'd just use class Obj(object): pass, but the advantage to this
> method is you can create an Obj like this:
> Obj(id="desktop", last=0, color=self.getColor(DESKTOP_COLOR))
> You can pass all the attributes you want the object to have this way.
> Nifty :)
Yup, that's basically what I was proposing in the pre-PEP:
I've let it slide for a bit here, but my intent is to make a patch that
puts something like the pre-PEP class into the collections module and
then send in the PEP. I've been kinda busy recently, and it's not quite
trivial since Bunch is in Python and currently the collections module is
in C, but hopefully in the next few weeks I'll have the time.
More information about the Python-list