Suppose I define a class:
class Foo(object): # children = [] # def __init__(self, *args, **kw): if kw: self.__dict__.update(kw) if args: self.chidlren = list(args)
In current syntax I have to write the folowing "initialization" code:
foo = \ Foo( Foo( Foo(x=3,y=4), Foo(x=5,y=6), x=4, y=5 ), x=1, y=2 )
I can't write this code as follows (it seems more natural for me):
foo = \ Foo( x=1, y=2, Foo( x=4, y=5, Foo(x=3,y=4), Foo(x=5,y=6)) ) )
Would be desirable to allow two equivalent forms of calling syntax in python:
<caller>(<positional_arguments>, <keyword_arguments>)
and
<caller>(<keyword_arguments>, <positional_arguments>)
?
Best regards, Zaur
On Tue, Sep 9, 2008 at 11:16 AM, Zaur Shibzoukhov szport@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/
Leif Walsh wrote:
On Tue, Sep 9, 2008 at 11:16 AM, Zaur Shibzoukhov szport@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.
Bruce Frederiksen schrieb:
Leif Walsh wrote:
On Tue, Sep 9, 2008 at 11:16 AM, Zaur Shibzoukhov szport@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.
Georg
Georg Brandl wrote:
Bruce Frederiksen schrieb:
Leif Walsh wrote:
On Tue, Sep 9, 2008 at 11:16 AM, Zaur Shibzoukhov szport@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