About calling syntax
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>(
On Tue, Sep 9, 2008 at 11:16 AM, Zaur Shibzoukhov
Would be desirable to allow two equivalent forms of calling syntax in python:
<caller>(
, ) and
<caller>(
, ) ?
I think you are talking about PEP 3102: http://www.python.org/dev/peps/pep-3102/ -- Cheers, Leif
Leif Walsh wrote:
On Tue, Sep 9, 2008 at 11:16 AM, Zaur Shibzoukhov
wrote: Would be desirable to allow two equivalent forms of calling syntax in python:
<caller>(
, ) and
<caller>(
, ) ?
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
wrote: Would be desirable to allow two equivalent forms of calling syntax in python:
<caller>(
, ) and
<caller>(
, ) ?
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 -- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.
Georg Brandl wrote:
Bruce Frederiksen schrieb:
Leif Walsh wrote:
On Tue, Sep 9, 2008 at 11:16 AM, Zaur Shibzoukhov
wrote: Would be desirable to allow two equivalent forms of calling syntax in python:
<caller>(
, ) and
<caller>(
, ) ?
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
participants (5)
-
Bruce Frederiksen
-
Georg Brandl
-
Leif Walsh
-
Talin
-
Zaur Shibzoukhov