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: 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" To: andrea crotti , python-list Subject: RE: amazing scope? Thread-Topic: amazing scope? Thread-Index: AQHNzut5aUGxwJb8jkGit93fIbNPkJgCwX7Q Date: Fri, 30 Nov 2012 19:21:55 +0000 References: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 andrea crotti=0D=0A> =0D=0A> I wrote a script, refactored it and then intro= ducing a bug as below:=0D=0A> =0D=0A> def record_things():=0D=0A> out= =2Ewrite("Hello world")=0D=0A> =0D=0A> if __name__ =3D=3D '__main__':=0D=0A= > with open('output', 'w') as out:=0D=0A> record_things()=0D=0A= > =0D=0A> =0D=0A> but the shocking thing is that it didn't actually stopped= working, it=0D=0A> still works perfectly!=0D=0A> =0D=0A> What my explanati= on might be is that the "out" is declared at module=0D=0A> level somehow,= =0D=0A> but that's not really intuitive and looks wrong, and works both on= =0D=0A> Python 2=2E7 and 3=2E2=2E=2E=0D=0A=0D=0AMakes sense to me=2E `out` = is declared in an if statement=2E If statements=0D=0Ahave no "scope" and it= is not in a function so it gets added to the =0D=0Amodule's namespace=2E= =0D=0A=0D=0A=0D=0A~Ramit=0D=0A=0D=0A=0D=0AThis email is confidential and su= bject to important disclaimers and=0D=0Aconditions including on offers for = the purchase or sale of=0D=0Asecurities, accuracy and completeness of infor= mation, viruses,=0D=0Aconfidentiality, legal privilege, and legal entity di= sclaimers,=0D=0Aavailable at http://www=2Ejpmorgan=2Ecom/pages/disclosures/= email=2E