Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes

Discussion in 'Python' started by Mitya Sirenef, Dec 12, 2012.

  1. 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/
     
    Mitya Sirenef, Dec 12, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Friedman
    Replies:
    0
    Views:
    128
    Jason Friedman
    Dec 11, 2012
  2. Ian Kelly
    Replies:
    0
    Views:
    147
    Ian Kelly
    Dec 11, 2012
  3. Dave Cinege
    Replies:
    0
    Views:
    178
    Dave Cinege
    Dec 11, 2012
  4. Ian Kelly
    Replies:
    0
    Views:
    161
    Ian Kelly
    Dec 11, 2012
  5. Ian Kelly
    Replies:
    0
    Views:
    145
    Ian Kelly
    Dec 11, 2012
Loading...

Share This Page