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


Groups > comp.lang.python > #82002

Re: The binding operator, and what gets bound to what

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'parameters': 0.04; 'cpython': 0.05; 'abuse': 0.07; 'python3': 0.07; 'definition,': 0.09; 'freedom,': 0.09; 'parameter': 0.09; 'restriction': 0.09; 'target,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '2.7.3': 0.16; '2.7:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'likewise': 0.16; 'statement.': 0.16; 'subject:bound': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'either.': 0.24; 'cc:2**0': 0.24; 'defined': 0.27; 'header :In-Reply-To:1': 0.27; 'function': 0.29; 'dec': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; '"",': 0.31; "d'aprano": 0.31; 'enforce': 0.31; 'steven': 0.31; 'subject:what': 0.31; 'file': 0.32; 'class': 0.32; 'linux': 0.33; 'url:python': 0.33; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; "didn't": 0.36; 'url:org': 0.36; 'should': 0.36; 'two': 0.37; 'nov': 0.38; 'pm,': 0.38; 'does': 0.39; 'future': 0.60; 'url:3': 0.61; 'first': 0.61; 'name': 0.63; 'subject:The': 0.64; 'more': 0.64; 'mar': 0.68; '2014,': 0.84; 'silently': 0.84; 'subject:gets': 0.84; 'url:reference': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=rfM5xtyY9H3KBEbw/fH5qcMc43stNw0d/cKqGpGfpyY=; b=AYYcI+iLVYlAIrTOIMneRf7kSFJ7JC7RSAOYtisKZACzgjJNnqE9ySmNMcukNRm8/6 6+fhtBZI7JennnFWL8lBKctXAXTg8+b3stMcL3euEA3UMVdrgtSOakf9Plknx6xewrmK gZ73fYovFIEfqOPSovw3E8E5BvFA3t3lALqIpUT2ugORNH+KPRE5A9iPTnO6bE4BWInB Q+oiiZGqQBeCKjnfc5pG6dNzKbHjj9pHYVX5ncdqWJ25BF6kPGNF2bXmEidgrevApDL6 MqB8umIsVlLtjWcCrdH2dwpX2CfLpRRrbx0x+0Jog6r1QZvvPe50CAUaH3xJXynbIMLS RpYA==
MIME-Version 1.0
X-Received by 10.50.62.104 with SMTP id x8mr2244334igr.2.1417783704466; Fri, 05 Dec 2014 04:48:24 -0800 (PST)
In-Reply-To <5481a63d$0$12992$c3e8da3$5496439d@news.astraweb.com>
References <aa74bd64-0e11-492d-ae2a-4b032a0408f9@googlegroups.com> <548113f3$0$13003$c3e8da3$5496439d@news.astraweb.com> <mailman.16608.1417757783.18130.python-list@python.org> <548180ae$0$13007$c3e8da3$5496439d@news.astraweb.com> <mailman.16622.1417781185.18130.python-list@python.org> <5481a63d$0$12992$c3e8da3$5496439d@news.astraweb.com>
Date Fri, 5 Dec 2014 23:48:24 +1100
Subject Re: The binding operator, and what gets bound to what
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16624.1417783712.18130.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417783712 news.xs4all.nl 2977 [2001:888:2000:d::a6]:48503
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82002

Show key headers only | View raw


On Fri, Dec 5, 2014 at 11:34 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
>> I don't think this is implementation-dependent.
>
> The docs say that it is:
>
> https://docs.python.org/3/reference/simple_stmts.html#the-global-statement
>
>     Names listed in a global statement MUST NOT [emphasis added] be
>     defined as formal parameters or in a for loop control target,
>     class definition, function definition, or import statement.
>
>     CPython implementation detail: The current implementation does not
>     enforce the two restrictions, but programs should not abuse this
>     freedom, as future implementations may enforce them or silently
>     change the meaning of the program.

Interesting, I didn't know that either.

But the first restriction _is_ enforced:

rosuav@sikorsky:~$ python3
Python 3.5.0a0 (default:23ab1197df0b, Nov 20 2014, 12:57:44)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def x(y):
...     global y
...
  File "<stdin>", line 2
SyntaxError: name 'y' is parameter and global

Likewise in CPython 2.7:

rosuav@sikorsky:~$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def x(y):
...     global y
...
  File "<stdin>", line 1
SyntaxError: name 'y' is local and global

ChrisA

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


Thread

About Modifying Globals LJ <luisjosenovoa@gmail.com> - 2014-12-04 12:09 -0800
  Re: About Modifying Globals Chris Angelico <rosuav@gmail.com> - 2014-12-05 07:22 +1100
  Re: About Modifying Globals Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-04 13:21 -0700
  Re: About Modifying Globals Dave Angel <davea@davea.name> - 2014-12-04 18:54 -0500
  Re: About Modifying Globals Chris Angelico <rosuav@gmail.com> - 2014-12-05 10:58 +1100
  Re: About Modifying Globals Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 13:09 +1100
    The binding operator, and what gets bound to what (was: About Modifying Globals) Ben Finney <ben+python@benfinney.id.au> - 2014-12-05 16:36 +1100
      Re: The binding operator, and what gets bound to what (was: About Modifying Globals) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 20:53 +1100
        Re: The binding operator, and what gets bound to what (was: About Modifying Globals) Chris Angelico <rosuav@gmail.com> - 2014-12-05 21:03 +1100
          Re: The binding operator, and what gets bound to what (was: About Modifying Globals) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 23:26 +1100
            Re: The binding operator, and what gets bound to what (was: About Modifying Globals) Chris Angelico <rosuav@gmail.com> - 2014-12-05 23:42 +1100
        Re: The binding operator, and what gets bound to what Ned Batchelder <ned@nedbatchelder.com> - 2014-12-05 07:06 -0500
          Re: The binding operator, and what gets bound to what Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 23:34 +1100
            Re: The binding operator, and what gets bound to what Chris Angelico <rosuav@gmail.com> - 2014-12-05 23:48 +1100
            Re: The binding operator, and what gets bound to what Ned Batchelder <ned@nedbatchelder.com> - 2014-12-05 07:56 -0500
  Re: About Modifying Globals "shiyao.ma" <i@introo.me> - 2014-12-05 10:53 +0800

csiph-web