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


Groups > comp.lang.python > #34104

RE: amazing scope?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '__name__': 0.07; 'completeness': 0.07; 'python': 0.09; "'w')": 0.09; 'explanation': 0.09; 'received:155': 0.09; 'script,': 0.09; 'wrong,': 0.09; 'bug': 0.10; 'def': 0.10; '2.7': 0.13; 'to:name:python-list': 0.15; "'__main__':": 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; "module's": 0.16; 'namespace.': 0.16; 'received:155.180': 0.16; 'received:155.180.234': 0.16; 'received:155.180.234.122': 0.16; 'received:159.53': 0.16; 'received:159.53.110': 0.16; 'received:159.53.110.174': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:se3.svr.bankone.net': 0.16; 'received:sj2.jpmchase.com': 0.16; 'received:svr.bankone.net': 0.16; 'refactored': 0.16; 'securities,': 0.16; 'somehow,': 0.16; 'statement.': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'module': 0.19; 'to:2**1': 0.23; 'received:169.254': 0.24; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'wrote': 0.26; 'accuracy': 0.27; 'declared': 0.29; 'statements': 0.29; 'received:169': 0.29; 'function': 0.30; 'sense': 0.31; 'gets': 0.32; 'to:addr:python-list': 0.33; 'subject:?': 0.35; 'really': 0.36; 'but': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; 'level': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'information,': 0.63; 'url:email': 0.63; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'below:': 0.71; 'sale': 0.76; 'andrea': 0.84; 'received:169.254.8': 0.84; 'shocking': 0.84; 'working,': 0.84
X-DKIM OpenDKIM Filter v2.1.3 sj2.jpmchase.com qAUJM7d3022335
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1354303327; bh=zSdRcUxZXdmwrGeVNMC3tMsPznZjEVBRgjre9Q6/LCU=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=b8CIbBDDhXt2Wlij1oJaec1jmzR3eC7bmdgzHJa0XqCQxJkiuJTCkj0paZX68y6UE s3bafurf/zXWBDtGmQmWvZFLZLKy9dJuGo/U3W5XnBuwikqbv+015jopumeyNzSnJy LFiwvlXmDaYUv9Dvw77eJQHNC4J1d2cDz6kEghN0=
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
To andrea crotti <andrea.crotti.0@gmail.com>, python-list <python-list@python.org>
Subject RE: amazing scope?
Thread-Topic amazing scope?
Thread-Index AQHNzut5aUGxwJb8jkGit93fIbNPkJgCwX7Q
Date Fri, 30 Nov 2012 19:21:55 +0000
References <CAF_E5JZ2infhbG+ZQVw7GTeSQMHH=6H06f3hsgSyfydVaqopsg@mail.gmail.com>
In-Reply-To <CAF_E5JZ2infhbG+ZQVw7GTeSQMHH=6H06f3hsgSyfydVaqopsg@mail.gmail.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.47]
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
Content-Type text/plain; charset="us-ascii"
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.390.1354303336.29569.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1354303336 news.xs4all.nl 6929 [2001:888:2000:d::a6]:41703
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34104

Show key headers only | View raw


andrea crotti
> 
> I wrote a script, refactored it and then introducing a bug as below:
> 
> def record_things():
>     out.write("Hello world")
> 
> if __name__ == '__main__':
>     with open('output', 'w') as out:
>         record_things()
> 
> 
> but the shocking thing is that it didn't actually stopped working, it
> still works perfectly!
> 
> What my explanation might be is that the "out" is declared at module
> level somehow,
> but that's not really intuitive and looks wrong, and works both on
> Python 2.7 and 3.2..

Makes sense to me. `out` is declared in an if statement. If statements
have no "scope" and it is not in a function so it gets added to the 
module's namespace.


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

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


Thread

RE: amazing scope? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-30 19:21 +0000

csiph-web