Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34668 > unrolled thread
| Started by | Mitya Sirenef <msirenef@lightbird.net> |
|---|---|
| First post | 2012-12-11 19:53 -0500 |
| Last post | 2012-12-11 19:53 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes Mitya Sirenef <msirenef@lightbird.net> - 2012-12-11 19:53 -0500
| From | Mitya Sirenef <msirenef@lightbird.net> |
|---|---|
| Date | 2012-12-11 19:53 -0500 |
| Subject | Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes |
| Message-ID | <mailman.759.1355273616.29569.python-list@python.org> |
On 12/11/2012 05:39 PM, Dave Cinege wrote: > On Tuesday 11 December 2012 16:53:12 Ian Kelly wrote: > >> Just out of curiosity, how old are we talking? enumerate was added in >> Python 2.3, which is nearly 10 years old. Prior to 2.2 I don't think >> it was even possible to subclass dict, which would make your Thesaurus >> implementation unusable, so are these systems running Python 2.2? > > I'm finally beyond 2.2 and getting rid of 2.4 soon. Just started using 2.6 5 > months ago. > > Thesaurus initially came about from me doing this: > class Global: > pass > g = Global() > > As a way to organize/consolidate global vars and eliminate the global > statement. I think that's the key issue here. I find that when code is well structured, you pretty much never have a need for global statements, anyway. By the way, the Thesaurus class reminds me of using the old recipe called 'Bunch': http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/ like this: b = Bunch(x=1) b.stuff = Bunch(y=2) b.stuff.y 2 I've also seen an answer on StackOverflow that uses automatic recursive 'Bunching': http://stackoverflow.com/questions/1123000/does-python-have-anonymous-classes I've seen another variation of recursive bunching, I think it was by Alex Martelli on StackOverflow, but I can't find it now, I believe it used defaultdict as part of it.. This approach can be handy sometimes but has drawbacks, as others have pointed out. I think the issue is that it's not a "solution for avoiding globals", which is not a problem in need of solution, but this can be a quick and dirty way to organize a few levels of dicts/Bunches and usually people come up with a custom variation on these recipes that suit their program. -- Lark's Tongue Guide to Python: http://lightbird.net/larks/
Back to top | Article view | comp.lang.python
csiph-web