[Python-ideas] Namespace creation with syntax short form
Steven D'Aprano
steve at pearwood.info
Fri Feb 13 14:38:49 CET 2015
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.
--
Steven
More information about the Python-ideas
mailing list