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

2013-01-10 Thread Duncan Booth
Dave Cinege d...@cinege.com wrote: You will notice that the code is disgusting simple. However I have found that this has completely changed the way I program in python. I've re-written some exiting programs using Thesaurus, and often relized 15-30% code reduction. Additionally I find the new

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

2013-01-10 Thread 88888 Dihedral
在 2013年1月10日星期四UTC+8下午7时34分23秒,Duncan Booth写道: Dave Cinege d...@cinege.com wrote: You will notice that the code is disgusting simple. However I have found that this has completely changed the way I program in python. I've re-written some exiting programs using Thesaurus, and often

ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2013-01-08 Thread Dave Cinege
Thesaurus: A different way to call a dictionary. Thesaurus is a new a dictionary subclass which allows calling keys as if they are class attributes and will search through nested objects recursively when __getitem__ is called. You will notice that the code is disgusting simple. However I have

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

2013-01-08 Thread Neal Becker
Did you intend to give anyone permission to use the code? I see only a copyright notice, but no permissions. -- http://mail.python.org/mailman/listinfo/python-list

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

2013-01-08 Thread Ian Kelly
On Tue, Jan 8, 2013 at 12:16 PM, Neal Becker ndbeck...@gmail.com wrote: Did you intend to give anyone permission to use the code? I see only a copyright notice, but no permissions. It also says Licence: python, Copyright notice may not be altered. Which suggests to me that the intent is that

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

2012-12-12 Thread D'Arcy J.M. Cain
On Wed, 12 Dec 2012 17:44:24 +1100 Chris Angelico ros...@gmail.com wrote: On Wed, Dec 12, 2012 at 5:34 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: and you consider this not productive, not worth my time. Code review with you must be *all* sorts of fun. He never asked

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

2012-12-12 Thread Dave Cinege
On Wednesday 12 December 2012 05:25:11 D'Arcy J.M. Cain wrote: As a 16yr OSS vet I know that for every 1 person that that actually creates something there will always be 2000 people to bitch about it. My skin isn't thin, I just don't give a shit to listen to anyone one that doesn't get it. The

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

2012-12-12 Thread Dave Cinege
On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote: I have a few critiques on the code. First, you might want to use __getattribute__ instead of __getattr__. Otherwise you'll end up File /home/dcinege/src/thesaurus/thesaurus.py, line 84, in __getattribute__ return

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

2012-12-12 Thread Ian Kelly
On Wed, Dec 12, 2012 at 12:20 PM, Dave Cinege d...@cinege.com wrote: On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote: I have a few critiques on the code. First, you might want to use __getattribute__ instead of __getattr__. Otherwise you'll end up File

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

2012-12-12 Thread Dave Cinege
On Wednesday 12 December 2012 15:42:36 Ian Kelly wrote: def __getattribute__(self, name): if name.startswith('__') and name.endswith('__'): return super(Thesaurus, self).__getattribute__(name) return self.__getitem__(name) Ian, Tested, and works as you advertised. Isn't

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

2012-12-12 Thread Ian Kelly
On Wed, Dec 12, 2012 at 3:20 PM, Dave Cinege d...@cinege.com wrote: On Wednesday 12 December 2012 15:42:36 Ian Kelly wrote: def __getattribute__(self, name): if name.startswith('__') and name.endswith('__'): return super(Thesaurus, self).__getattribute__(name) return

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

2012-12-12 Thread Mark Lawrence
On 12/12/2012 18:13, Dave Cinege wrote: On Wednesday 12 December 2012 05:25:11 D'Arcy J.M. Cain wrote: As a 16yr OSS vet I know that for every 1 person that that actually creates something there will always be 2000 people to bitch about it. My skin isn't thin, I just don't give a shit to listen

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

2012-12-12 Thread Steven D'Aprano
On Wed, 12 Dec 2012 23:56:24 +, Mark Lawrence wrote: Please don't place responses like this. The Python community prides itself on tolerance. If you don't wish to follow that recommendation please go to an alternative site. Well, I must say, I think that you've just won an award for

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

2012-12-12 Thread Steven D'Aprano
On Wed, 12 Dec 2012 17:20:53 -0500, Dave Cinege wrote: Isn't super() depreciated? Heavens no. super() is the recommended way to do inheritance, and the *only* way to correctly do multiple inheritance[1]. What makes you think that it has been deprecated? [...] To me for i in range(len(l))

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

2012-12-12 Thread Chris Angelico
On Thu, Dec 13, 2012 at 11:30 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 12 Dec 2012 17:20:53 -0500, Dave Cinege wrote: To me for i in range(len(l)) seems like simpler, faster, tighter code for this now. * the version with enumerate makes the intent more clear:

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

2012-12-12 Thread Dave Cinege
On Wednesday 12 December 2012 20:14:08 Chris Angelico wrote: Ok enough already, I'll use the frigging thing! Be happy I'm at least still not coding for python 1.5. To add to this: Using enumerate gives the possibility (don't know if any current interpreter takes advantage or not, but a future

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

2012-12-12 Thread Terry Reedy
On 12/12/2012 7:30 PM, Steven D'Aprano wrote: On Wed, 12 Dec 2012 17:20:53 -0500, Dave Cinege wrote: Isn't super() depreciated? Heavens no. super() is the recommended way to do inheritance, and the *only* way to correctly do multiple inheritance[1]. Indeed. Rather than super() being

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

2012-12-12 Thread Dave Cinege
Version 20121212 #!/usr/bin/env python thesaurus.py 2012-12-12 Copyright (c) 2012 Dave Cinege Licence: PSF Licence, Copyright notice may not be altered. Thesaurus: A different way to call a dictionary. Thesaurus is a new a dictionary subclass which allows calling keys as if they are class

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

2012-12-12 Thread Dave Cinege
On Monday 10 December 2012 23:08:24 Jason Friedman wrote: 2) Posting your code at ActiveState.com. If someone wants to please do. I'm back to being completely overloaded with normal work now. The v20121212 release based on the last few days comments is as far as I will go with this now. Dave

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

2012-12-11 Thread Steven D'Aprano
On Mon, 10 Dec 2012 22:48:50 -0500, Dave Cinege wrote: Thesaurus: A different way to call a dictionary. Is this intended as a ready-for-production class? Thesaurus is a new a dictionary subclass which allows calling keys as if they are class attributes and will search through nested objects

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

2012-12-11 Thread Jean-Michel Pichavant
- Original Message - Thesaurus: A different way to call a dictionary. Thesaurus is a new a dictionary subclass which allows calling keys as if they are class attributes and will search through nested objects recursively when __getitem__ is called. You will notice that the code

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

2012-12-11 Thread Dave Cinege
On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote: running into bugs like this: thes = Thesaurus() thes.update = 'now' thes.update built-in method update of Thesaurus object at 0x01DB30C8 I've noticed this but it's mostly pointless, as meaningful code does work. (Also you stepped on

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

2012-12-11 Thread Dave Cinege
On Tuesday 11 December 2012 03:12:19 Steven D'Aprano wrote: Is this intended as a ready-for-production class? For me, yes. In production code. py d = Thesaurus() py d['spam'] = {} Maybe because spam is type dict instead of type thes??? import thesaurus thes = thesaurus.Thesaurus t =

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

2012-12-11 Thread Ian Kelly
On Tue, Dec 11, 2012 at 1:57 PM, Dave Cinege d...@linkscape.net wrote: On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote: Second, in __getitem__ you start a loop with for i in range(len(l)):, and then you use i as an index into l several times. It would be cleaner and more Pythonic to do

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

2012-12-11 Thread Ian Kelly
On Tue, Dec 11, 2012 at 2:53 PM, Ian Kelly ian.g.ke...@gmail.com wrote: and then I ran the examples, and the output was unchanged. As Steven pointed out, I don't see how that first branch could succeed anyway, since self.data is never defined. It occurs to me that the UserDict class does have

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

2012-12-11 Thread Dave Cinege
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

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

2012-12-11 Thread Cameron Simpson
On 11Dec2012 15:57, Dave Cinege d...@linkscape.net wrote: | On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote: | running into bugs like this: | thes = Thesaurus() | thes.update = 'now' | thes.update | | built-in method update of Thesaurus object at 0x01DB30C8 | | I've noticed this

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

2012-12-11 Thread Dave Cinege
On Tuesday 11 December 2012 17:39:12 Dave Cinege wrote: My memory is getting jogged more why did some things: raise KeyError(key + ' [%s]' % i) I did this to specificly give you the indice that failed recursion but provide the entire key name as it was provided to __getitem__ So if:

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

2012-12-11 Thread Mitya Sirenef
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

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

2012-12-11 Thread Mitya Sirenef
On 12/11/2012 07:53 PM, Mitya Sirenef wrote: 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

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

2012-12-11 Thread Steven D'Aprano
On Tue, 11 Dec 2012 16:08:34 -0500, Dave Cinege wrote: On Tuesday 11 December 2012 03:12:19 Steven D'Aprano wrote: Is this intended as a ready-for-production class? For me, yes. In production code. py d = Thesaurus() py d['spam'] = {} Maybe because spam is type dict instead of type

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

2012-12-11 Thread Steven D'Aprano
On Tue, 11 Dec 2012 16:08:34 -0500, Dave Cinege wrote: On Tuesday 11 December 2012 03:12:19 Steven D'Aprano wrote: Is this intended as a ready-for-production class? For me, yes. In production code. py d = Thesaurus() py d['spam'] = {} Maybe because spam is type dict instead of type

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

2012-12-11 Thread Chris Angelico
On Wed, Dec 12, 2012 at 5:34 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: So, let's see now... I identified that your Thesaurus code: * will fail silently; * contains dead code that is never used; * contains redundant code that is pointless; * hides errors in the caller's

ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-10 Thread Dave Cinege
Thesaurus: A different way to call a dictionary. Thesaurus is a new a dictionary subclass which allows calling keys as if they are class attributes and will search through nested objects recursively when __getitem__ is called. You will notice that the code is disgusting simple. However I have

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

2012-12-10 Thread Jason Friedman
Thesaurus is a new a dictionary subclass which allows calling keys as if they are class attributes and will search through nested objects recursively when __getitem__ is called. Good stuff. You might consider: 1) Licensing under an OSI-approved license

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

2012-12-10 Thread Ian Kelly
On Mon, Dec 10, 2012 at 8:48 PM, Dave Cinege d...@cinege.com wrote: Thesaurus: A different way to call a dictionary. Thesaurus is a new a dictionary subclass which allows calling keys as if they are class attributes and will search through nested objects recursively when __getitem__ is