Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34656 > unrolled thread

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

Started byDave Cinege <dave@cinege.com>
First post2012-12-11 17:39 -0500
Last post2012-12-11 17:39 -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.


Contents

  Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes Dave Cinege <dave@cinege.com> - 2012-12-11 17:39 -0500

#34656 — Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

FromDave Cinege <dave@cinege.com>
Date2012-12-11 17:39 -0500
SubjectRe: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes
Message-ID<mailman.749.1355265558.29569.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web