Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes
On 11Dec2012 15:57, Dave Cinege <firstname.lastname@example.org> 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 but it's mostly pointless, as meaningful code does work.
| (Also you stepped on the existing 'update()' dictionary method.)
I think that was a deliberate choice of name by Ian.
I've got a class like Thesaurus that subclasses dict and maps attributes
to dictionary elements (with a few special purpose tweaks I could go into
if anyone cares). I made a deliberate decision to only map UPPERCASE
attributes to dict keys to avoid exactly the kind of conflict above,
thes.update = 'now'
must either trash the dict.update method _or_ fail to present .update as
'now'. Both have their downsides. So at the cost of shoutier but still
effective code I accepted only .UPPERCASE attribute names as mapping to
This compromise also makes subclassing much easier, because the
subclasser is free to use conventional lowercase attribute names.
Cameron Simpson <email@example.com>
Thousands at his bidding speed,
And post o'er land and ocean without rest - Milton
|All times are GMT. The time now is 05:01 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.