Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #49806

Re: Why this code works in python3, but not python 2:

Path csiph.com!usenet.pasdenom.info!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <joshua.landau.ws@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'syntax': 0.04; 'subject:code': 0.07; 'subject:Why': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'accepting': 0.14; '**kwargs):': 0.16; 'gained': 0.16; 'keyword.': 0.16; 'positional': 0.16; 'subject:python3': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'anyone': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'does': 0.39; 'skip:* 10': 0.61; 'july': 0.63; 'to:addr:gmail.com': 0.65; 'subject:this': 0.83; 'subject::': 0.85; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=ehZz09B1HigsZ49SMvzR4B6fP4Fw3CoLsMU8g1Ssrag=; b=iUCmT/KItdpSAvQA3DuhPO+mthx0mGwOf+1qx/aV2D0CKUiGXoZP32RWI6btXY1Utl cD04rR/YKQ8h++gh4tEhLT0yJ509qf5M96Aq1IM5OwPN6kGh0QhvLA1rhO5Uc8o+t17c HrCkRS3bOTHxvAt/DD2hASNLyvGcQmxmt37Wfzac/lknvCIpu2wxyatOUtBSbeOMh4hi aElu0JLZ7HBsv/vPyhJxIE9aAIh+kcU8qIixLnQlODu0P2WJKn68wdeukcDnSNoVguEQ rpJbyNxi/b9B6eJjrIdt9nUlF3R3QtgiSyuGO+TWBskYNhxtZBbwl/cb7ubik68he4eM UnJA==
X-Received by 10.112.182.39 with SMTP id eb7mr2579667lbc.30.1372911186226; Wed, 03 Jul 2013 21:13:06 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <e0ffc562-4016-4b5d-88c3-5a115da16906@googlegroups.com>
References <e0ffc562-4016-4b5d-88c3-5a115da16906@googlegroups.com>
From Joshua Landau <joshua.landau.ws@gmail.com>
Date Thu, 4 Jul 2013 05:12:26 +0100
Subject Re: Why this code works in python3, but not python 2:
To Maciej Dziardziel <fiedzia@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4202.1372911189.3114.python-list@python.org> (permalink)
Lines 13
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372911189 news.xs4all.nl 15886 [2001:888:2000:d::a6]:43809
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49806

Show key headers only | View raw


On 4 July 2013 04:52, Maciej Dziardziel <fiedzia@gmail.com> wrote:
> Out of curiosity: Does anyone know why the code below is valid in python3, but not python2:
>
> def foo(*args, bar=1, **kwargs):
>     pass

Python 3 gained syntax for keyword-only arguments.

Try "foo(1)" and it will fail -- "bar" needs to be given as a keyword.
This is because it comes after a *-expression. You can also do "def
foo(*, bar=1)" if you want bar to be keyword-only without accepting
any number of positional arguments. Python 2 does not have these, and
doesn't understand the syntax for them.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why this code works in python3, but not python 2: Maciej Dziardziel <fiedzia@gmail.com> - 2013-07-03 20:52 -0700
  Re: Why this code works in python3, but not python 2: alex23 <wuwei23@gmail.com> - 2013-07-04 14:05 +1000
    Re: Why this code works in python3, but not python 2: Maciej Dziardziel <fiedzia@gmail.com> - 2013-07-03 21:31 -0700
  Re: Why this code works in python3, but not python 2: Chris Angelico <rosuav@gmail.com> - 2013-07-04 14:10 +1000
  Re: Why this code works in python3, but not python 2: Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-04 05:12 +0100
    Re: Why this code works in python3, but not python 2: alex23 <wuwei23@gmail.com> - 2013-07-04 14:47 +1000
      Re: Why this code works in python3, but not python 2: Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-04 06:10 +0100

csiph-web