Cool object trick
Steven Bethard
steven.bethard at gmail.com
Sun Dec 12 23:25:27 EST 2004
dataangel wrote:
> 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:
http://mail.python.org/pipermail/python-list/2004-November/252621.html
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.
Steve
More information about the Python-list
mailing list