[Python-ideas] Namespace creation with syntax short form
Peter Otten
__peter__ at web.de
Fri Feb 13 15:00:58 CET 2015
Steven D'Aprano wrote:
> On Fri, Feb 13, 2015 at 02:20:48PM +0100, Peter Otten wrote:
>
>> a:1, b:2, c:3
>>
>> has to create an object with three attributes "a", "b", and "c" and
>
> This is ambiguous. Is it one object with three attributes, or a tuple of
> three namespace objects, each with one attribute?
>
>
>> :a, :b, :c = x
>>
>> works on any x with three attributes "a", "b", and "c".
>> Implementationwise
>
> I don't like the way that the colon jumps around from after the name to
> before the name. I don't like the way attributes are sometimes written
> with a dot and sometimes a colon:
>
> x = a:1, b:2
> process(x.a)
> process(x:b) # oops.
>
>
> I think it is awfully mysterious syntax and beginners are going to have
> a terrible time working out when they should use dot and when they
> should use colon.
I regret that I let Andrew lure me into a discussion of those details so
soon.
The point of my original answer was that if an acceptable syntax can be
found real code can profit from it.
Personally, I would be OK with limiting this construct to return statements
and the lhs of an assignment, but I doubt that this will gather the
necessary support.
More information about the Python-ideas
mailing list