[BangPypers] Favorite tips/techniques

Anand Chitipothu anandology at gmail.com
Tue Sep 10 06:48:13 CEST 2013


On Tue, Sep 10, 2013 at 10:09 AM, Noufal Ibrahim <noufal at nibrahim.net.in>wrote:

> Shabda Raaj <shabda at agiliq.com> writes:
>
> >> I generally like to use attributes instead of keys.
> >
> > If you are parsing json, aren't you limited to using keys?
>
> Of course. I was making a general statement about attributes vs. keys.
>
> > The bunch pattern can fix this, but its not widely known/used, so I
> > don't use it as frequently as I would like.
>
> Yes. It's quite neat.
>

web.py has something similar, but it works both like a dict and object at
the same time. More like a javascript object.

https://github.com/webpy/webpy/blob/master/web/utils.py#L52

Couple of issues with the Bunch pattern:

* it is hard to check for existence of a key
* hard to iterate over the keys
* how do you convert a bunch object into JSON?

Anand


More information about the BangPypers mailing list