Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: A newbie quesiton: local variable in a nested funciton Date: Sun, 27 Dec 2015 17:22:45 +1100 Lines: 24 Message-ID: References: <701dd0e6-a9c1-4aa9-a3a2-6607cd3f3759@googlegroups.com> <661a13a1-8084-41ca-b458-297462dc3367@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de Y257U+oOTK1eeQbW8OWIRg5rIHYOswMVKFa7PsgGuJ4A== 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; 'received:209.85.223': 0.03; '#include': 0.07; '*not*': 0.07; 'cc:addr:python-list': 0.09; 'follows.': 0.09; 'imports': 0.09; 'python.': 0.11; 'directive': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'namespace,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:variable': 0.16; 'wrote:': 0.16; 'flexibility': 0.18; 'instance,': 0.18; 'language': 0.19; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(all': 0.22; 'function,': 0.22; '(or': 0.23; 'dec': 0.23; "python's": 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'define': 0.27; 'least': 0.27; 'question': 0.27; 'message- id:@mail.gmail.com': 0.27; 'executing': 0.27; '(it': 0.29; 'path,': 0.29; 'rules': 0.31; "can't": 0.32; 'maybe': 0.33; 'class': 0.33; 'definition': 0.34; 'file': 0.34; 'received:google.com': 0.35; 'next': 0.35; 'level': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'why': 0.39; 'does': 0.39; 'some': 0.40; 'your': 0.60; 'matter': 0.63; 'necessarily': 0.63; "they're": 0.66; 'chrisa': 0.84; 'complexity': 0.84; 'ultimately,': 0.84; 'to:none': 0.91; 'hand,': 0.97 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=rfam081W1Y3UOr0U6G073G6J78ZmZTjNjIucxVWQvnA=; b=hots5jJ4e+L+L9zeN5/8UcDln7VDzqzIFzAUdBCMzGyvfL4OwM76cyu8+HBzFUj2RW pEms9Fw77WWfJ1Y2T4eneoQ8PvgofstzOpsEVvBZmwnZQNfMSmHRK8VF+L/6QFWra1su BApgGKwZ+QKKtWIXbrblTw70ZCvkI4+spO6qfcY90dXcB+T9kzENSMXEmfCu4/PqMO/E gslvEZb0JxcgvVlEYlLgdJcZW+ad75hjHfkc9JYmJvH0T0tqt6ynohSLyityVm8G88KZ RP2lN1J8Ugfi7wZk7Kz1pwRO7gLrBrzeb8q71t/ZtR/iCaODSFWo6/lU8GXKf0qfdVL6 TAng== X-Received: by 10.107.47.162 with SMTP id v34mr1353019iov.19.1451197365557; Sat, 26 Dec 2015 22:22:45 -0800 (PST) In-Reply-To: <661a13a1-8084-41ca-b458-297462dc3367@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100902 On Sun, Dec 27, 2015 at 3:05 PM, wrote: >> Python's flexibility and simplicity are a huge part of why I love the >> language so much. > > simplicity? Maybe because you are soooo familiar with Python. It's not to me, at least at this moment. Please see my next question follows. > I define "simplicity" in terms of the number and complexity of the rules you have to keep in your head. It's not necessarily the best thing to do; for instance, a C-style #include directive is *extremely* simple (it is literally "drop the file contents in at this location"), but I prefer Python's semantics. On the other hand, PHP's include directive is *not* simple; in many ways it behaves like C's #include, but it can't be used inside class definitions, and if used in a function, some of what it does is at top level and some is inside the function. Python's rules for imports (whether they're "import X" or "from X import Y") include a somewhat complicated definition of search path, but ultimately, it's a matter of hunting down a module and executing it (all of it) in its own namespace, and then giving you a reference to sys.modules["X"] (or sys.modules["X"].Y for a from-import). ChrisA