[Python-3000] Stars (original) (raw)
Thomas Wouters thomas at python.org
Thu Mar 1 08:45:07 CET 2007
- Previous message: [Python-3000] Stars
- Next message: [Python-3000] PEP Draft: Enhancing the buffer protcol
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 3/1/07, Raymond Hettinger <raymond.hettinger at verizon.net> wrote:
What we have now: def f(a, b, *args, **dict(c=1)): # Yuck! What we really need: def f(a, b, *args, **, c=1): # Two stars spell dictionary. What I heard was planned instead: def f(a, b, *args, *, c=1): # One star spells iterable.
Nope. You can only have one one-star and one two-star. If you want keyword-only arguments and arbitrary positional arguments, you can just do it (in Py3k, and it will probably be backported to 2.6.)
def foo(a, b, *args, c=1): return a, b, args, c ... foo(1, 2) (1, 2, (), 1) foo(1, 2, 3, 4, c=5) (1, 2, (3, 4), 5)
The one-star-only syntax is only if you don't want arbitrary positional arguments:
def foo(a, b, *, c=1): return a, b, c ... foo(1, 2) (1, 2, 1) foo(1, 2, 5) Traceback (most recent call last): File "", line 1, in TypeError: foo() takes exactly 2 positional arguments (3 given) foo(1, 2, c=5) (1, 2, 5)
-- Thomas Wouters <thomas at python.org>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-3000/attachments/20070301/c07eb8e1/attachment.html
- Previous message: [Python-3000] Stars
- Next message: [Python-3000] PEP Draft: Enhancing the buffer protcol
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]