[Python-ideas] Dict-like object with property access

Massimo Di Pierro massimo.dipierro at gmail.com
Mon Jan 30 17:22:26 CET 2012

I do not think the issue is whether the people who use that semantic understand it or not. I can assure you they do and they know when it is appropriate to use it or not. The issue is whether there is any value is making it faster by including it in python or not. Because of the increasing popularity of JS I think new users are starting to expect something like it out of the box.  Anyway, Guido's object about the "clear" method (and other methods) is the most serious problem. One way around could be preventing keys which conflicts with the method names.


On Jan 30, 2012, at 10:01 AM, Masklinn wrote:

> On 2012-01-30, at 15:58 , Massimo Di Pierro wrote:
>> In web2py we have a class called Storage. (web.py has a similar class too).
>> works exactly like this except that if you do mydict.someprop and someprop does not exist returns None (which plays the role of JS undefined) instead of raining an exception. Users like this a lot because they can do:
>>   a = mydict.somevalue or 'somedefault'
>> which new users find more readable than
>>  a = mydict.get('somevalue','somedefault')
> And with completely different semantics, as a falsy value (empty string, 0, empty collection, None, etc…) will yield the default for the first case, but not for the second case.

More information about the Python-ideas mailing list