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

Massimo Di Pierro massimo.dipierro at gmail.com
Wed Feb 1 14:32:45 CET 2012


Using x:[....] wouldn't it create ambiguities when parsing (lambda x:[....])?

How about x. as a shortcut for x.__dict__ so we can do

x.key -> x.__dict__['key'] 
x.[key] -> x.__dict__[key]
x..keys() -> x.__dict__.keys()
x..values() -> x.__dict__.values()

for attribute in x.:
     print 'x.'+attribute

and leave open the possibility of 3 dots for for ranges
1...5 -> range(1,5)
1,2...10 -> range(1,10,2-1)



On Feb 1, 2012, at 7:05 AM, Paul Moore wrote:

> On 1 February 2012 11:33, Joao S. O. Bueno <jsbueno at python.org.br> wrote:
>> Still, there should be something with a closing token.
>> Try to imagine three of these in a chain, if the syntax is a colon:
>> 
>> name1:name2:name3:name4 -> which could mean either of:
>> 
>> name1:(name2:(name3:name4)), (name1:name2):(name3.name4)
>> and so on  - (not to mention other expressions involving names, though these
>> would be less ambiguous due to to operator precedence.
> 
> No more so than a.b.c.d.e
> 
> I would expect a:b to behave exactly the same as a.b, Except that it
> uses getitem rather than getattr under the hood (was that the
> proposal? I'm completely confused by now as to what this new syntax is
> intended to achieve...)
> 
> But I don't like the idea in any case, so I remain -1 on the whole proposal.
> 
> Paul.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas




More information about the Python-ideas mailing list