Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!rt.uk.eu.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'main()': 0.07; 'anyway': 0.11; 'dec': 0.15; 'sat,': 0.15; '"int': 0.16; 'earlier.': 0.16; 'foo;': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guilty': 0.16; 'wrote:': 0.17; 'module': 0.19; 'bit': 0.21; 'fine,': 0.22; 'void': 0.22; 'defined': 0.22; 'this:': 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.30; 'stuff': 0.30; 'code': 0.31; 'int': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'same.': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'different': 0.63; 'andrea': 0.84; 'suprise': 0.84 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:to :content-type; bh=J2vvvHcGHIalJdo1bFGFjWBl4/j9qxWoKEfYf2tj8vc=; b=ONbMUrqYL0UQZr2yutR5YxruegH9CXdbYZtStkjVDz+mFVfKvHf/j6VPVwbDAhmEdQ 0IeQK+amNh0jGZSYWT0EpR6Yom4H6HiXEThz5/+MRPBybu2l6uNLiJvFoVcsbtvY7Mv9 2FwiuMWVWOwAwufZl7uLGl5Z+cOwE4z3ZqOFdr1VLW8r2xTC1ZyoAtAdDoumcz+RHRnF /4B5QrVme9m65EXaCIz7A3pqOmJGJgFJ2hRXE/dPXMonwG68vOTSDZzaSNxEHhrLl4LW uQckQ6jC1kcyyMEDfl6XipGf2sEneCeGpPiHCq4bMjlOMZhUXdyWp4nNHCHYDRFl568f EIdg== MIME-Version: 1.0 In-Reply-To: References: Date: Sat, 1 Dec 2012 03:08:45 +1100 Subject: Re: amazing scope? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354291733 news.xs4all.nl 6902 [2001:888:2000:d::a6]:34488 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34099 On Sat, Dec 1, 2012 at 3:05 AM, andrea crotti wrote: > Well I knew that this works fine, even if I feel a bit guilty to do > this, and better is: > > foo = 'bar' if some_condition else 'baz' > > Anyway for me the suprise is that something that is defined *later* at > the module scope is found in a function which is defined *earlier*. It's assigned to earlier. It's no different from C code like this: int foo; void blah() { /* do stuff with foo */ } int main() { foo = 1; } In Python, the "int foo;" is implicit, but the scope is the same. ChrisA