Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes

Discussion in 'Python' started by Dave Cinege, Dec 11, 2012.

  1. Dave Cinege

    Dave Cinege Guest

    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.

    After a brain fart one day I expanded this to some simple recursion and felt I
    was onto something as my entire life changed with how easy it now was to build
    output strings.

    As you noted it was not possible to subclass dict, so I first tried with a
    class, and you run into recursion hell with __setatrib__ to which i think
    there is no fix.

    I then made a UserDict version. Then when I moved mostly to 2.6 I could do a
    proper dict subclass.

    So I believe you're actually correct here....

    if isinstance(l[0], (dict, Thesaurus)):
    a = self.data

    Looks like an artifact from my UserDict version and was needed. :-(

    class UserDict:
    def __init__(self, dict=None, **kwargs):
    self.data = {}

    Thanks for this. You'll see from the version number I wrote this 3 months ago
    so it's not 100% fresh in my mind. I'm releasing it now because a python coder
    I contracted to pick up some slack for me saw this and went ape at how much he
    liked it...and that prompted me to finally get it out into the wild.

    As for in depth discussion and enhancement to this, I lack the time.

    Dave
    Dave Cinege, Dec 11, 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:
    104
    Jason Friedman
    Dec 11, 2012
  2. Ian Kelly
    Replies:
    0
    Views:
    123
    Ian Kelly
    Dec 11, 2012
  3. Dave Cinege
    Replies:
    0
    Views:
    153
    Dave Cinege
    Dec 11, 2012
  4. Ian Kelly
    Replies:
    0
    Views:
    144
    Ian Kelly
    Dec 11, 2012
  5. Ian Kelly
    Replies:
    0
    Views:
    120
    Ian Kelly
    Dec 11, 2012
Loading...

Share This Page