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: 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: References: From: Joshua Landau Date: Thu, 4 Jul 2013 05:12:26 +0100 Subject: Re: Why this code works in python3, but not python 2: To: Maciej Dziardziel Content-Type: text/plain; charset=UTF-8 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 4 July 2013 04:52, Maciej Dziardziel 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.