[Python-ideas] About calling syntax
Talin
talin at acm.org
Wed Sep 10 06:19:52 CEST 2008
Georg Brandl wrote:
> Bruce Frederiksen schrieb:
>> Leif Walsh wrote:
>>> On Tue, Sep 9, 2008 at 11:16 AM, Zaur Shibzoukhov <szport at gmail.com> wrote:
>>>
>>>> Would be desirable to allow two equivalent forms of calling syntax in python:
>>>>
>>>> <caller>(<positional_arguments>, <keyword_arguments>)
>>>>
>>>> and
>>>>
>>>> <caller>(<keyword_arguments>, <positional_arguments>)
>>>>
>>>> ?
>>>>
>>> I think you are talking about PEP 3102: http://www.python.org/dev/peps/pep-3102/
>>>
>> I don't think so. This PEP does not affect the syntax for calling a
>> function.
>
> It does, in that you can do
>
> foo(*args, flag=True)
>
> which is currently a SyntaxError.
>
> However, exchanging poisitional and keyword arguments is not in the scope of
> the PEP, and isn't likely to have any future at all -- it's just too ambiguous
> when the called object has named arguments instead of a catch-all *args in
> its signature.
Correct.
However, to address the OP's question, do this instead:
foo = \
Foo(x=1, y=2,
[Foo(
x=4, y=5,
[Foo(x=3,y=4),
Foo(x=5,y=6))]
)]
)
Or, have Foo() return a callable:
foo = \
Foo(x=1, y=2)(
Foo(x=4, y=5)(
Foo(x=3,y=4)(),
Foo(x=5,y=6)())
)
)
Or any number of other variations...
-- Talin
>
> Georg
>
More information about the Python-ideas
mailing list