[Python-ideas] Make obj[] valid syntax?
Thomas Heller
theller at ctypes.org
Wed Nov 14 20:22:48 CET 2007
Guido van Rossum schrieb:
> So what?
>
> x =
>
> is not equivalent to
>
> x = ()
I won't argue this with you ;-)
>> > Oleg Broytmann schrieb:
>>> > > On Wed, Nov 14, 2007 at 07:29:52PM +0100, Thomas Heller wrote:
>>>> > >> 'obj[]' should behave like 'obj[()]' does:
>>> > >
>>> > > I remember it was discussed and rejected a year or two ago. Still -1
>>> > > from me. Explicit [()] is better than implicit [].
>> >
>> > However: obj[(1, 2, 3)] is the same as obj[1, 2, 3]
>
> 1, 2, 3 is a tuple, and () is a tuple, should there be a syntax for an
> empty tuple without parenthesis?
>
> Thomas, there were many arguments in the previous discussion. This one
> was there, too. But finally the proposal was rejected.
I see that my proposal probably won't fly. This encourages me to describe
my full wish, just for fun:
It would be nice if I could have positional AND keyword arguments for __getitem__
and __setitem__, so that I could write code like this (COM has named parameters also):
x = obj.prop[1, 2, lcid=0]
x = obj.prop[]
obj.prop[1, 2, lcid=0] = "foo"
obj.prop[] = "foo"
or even
x = obj.prop[1, 2, lcid=0]
x = obj.prop[]
x = obj.prop # same as previous line (now how would THAT work?)
obj.prop[1, 2, lcid=0] = "foo"
obj.prop[] = "foo"
obj.prop = "foo" # same as previous line
I retract my proposal.
VB-ly, yours
Thomas
More information about the Python-ideas
mailing list