extra positional arguments before optional parameters syntax

Discussion in 'Python' started by MisterWilliam, Jun 18, 2008.

  1. I noticed that in PEP 3105, the PEP about turning print to print(),
    the syntax for print() is defined as follows:
    def print(*args, sep=' ', end='\n', file=None)

    Ignoring the fact that print is a reserved keyword in python, this is
    not valid python because extra positional arguments (*args), cannot
    come before optional parameters (sep=' ', end='\n', file=None).

    >>> def f(*args, sep=' ', end='\n', file=None):

    File "<stdin>", line 1
    def f(*args, sep=' ', end='\n', file=None):
    ^
    SyntaxError: invalid syntax

    Am I misunderstanding something? Is this type of syntax suppose to be
    allowed in a future version of Python? (I can't find anything about
    this through my searching.) This kind of syntax seems useful,
    especially one wants to overwrite the new function print().

    Thanks,
    William Chang
     
    MisterWilliam, Jun 18, 2008
    #1
    1. Advertising

  2. On Jun 18, 5:25 pm, MisterWilliam <> wrote:

    > I noticed that in PEP 3105, the PEP about turning print to print(),
    > the syntax for print() is defined as follows:
    > def print(*args, sep=' ', end='\n', file=None)
    >
    > Ignoring the fact that print is a reserved keyword in python, this is
    > not valid python because extra positional arguments (*args), cannot
    > come before optional parameters (sep=' ', end='\n', file=None).
    >
    > >>> def f(*args, sep=' ', end='\n', file=None):

    >
    > File "<stdin>", line 1
    > def f(*args, sep=' ', end='\n', file=None):
    > ^
    > SyntaxError: invalid syntax
    >
    > Am I misunderstanding something? Is this type of syntax suppose to be
    > allowed in a future version of Python? (I can't find anything about
    > this through my searching.)


    You didn't search hard enough; it's three PEPs earlier:

    http://www.python.org/dev/peps/pep-3102/

    George
     
    George Sakkis, Jun 18, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tomi Silander
    Replies:
    3
    Views:
    962
    Grant Edwards
    Apr 6, 2005
  2. I.M. Postor
    Replies:
    2
    Views:
    608
    I.M. Postor
    Sep 27, 2006
  3. Andy

    Positional Grouping

    Andy, Jan 10, 2007, in forum: XML
    Replies:
    0
    Views:
    466
  4. Peter Otten
    Replies:
    1
    Views:
    495
    rantingrick
    Feb 1, 2011
  5. Johannes Bauer
    Replies:
    0
    Views:
    171
    Johannes Bauer
    Nov 20, 2012
Loading...

Share This Page