Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Question about math.pi is mutable Date: Mon, 9 Nov 2015 23:36:54 +1100 Lines: 50 Message-ID: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <5640038b$0$1612$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de o1FHwkkXsd1ck3T85mlAoAZ23R3jk3Cg0oGUWxu3qPIw== 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; 'none,': 0.05; 'removes': 0.05; 'subject:Question': 0.05; 'used.': 0.05; "'a'": 0.07; 'assignment': 0.07; 'bug.': 0.07; 'correct.': 0.07; 'table.': 0.07; 'cc:addr:python-list': 0.09; '#print': 0.09; 'exist.': 0.09; 'none"': 0.09; 'python': 0.10; "hasn't": 0.15; '2",': 0.16; 'attributes,': 0.16; 'encountered.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lookups.': 0.16; 'nameerror': 0.16; 'namespace,': 0.16; 'not;': 0.16; 'received:209.85.213.176': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'utterly': 0.16; 'wrote:': 0.16; 'hack': 0.18; 'variable': 0.18; 'language': 0.19; 'changes': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(the': 0.22; 'meant': 0.22; '(a)': 0.22; 'function,': 0.22; 'bit': 0.23; 'unlike': 0.23; 'tried': 0.24; 'implemented': 0.24; 'header:In- Reply-To:1': 0.24; 'mon,': 0.24; 'sort': 0.25; 'module': 0.25; "i've": 0.25; "doesn't": 0.26; 'sense': 0.26; 'skip:" 20': 0.26; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'actual': 0.28; 'attempting': 0.29; 'consequence': 0.29; 'dictionary': 0.29; 'exists,': 0.29; 'modified,': 0.29; 'referenced': 0.29; 'code:': 0.29; 'print': 0.30; 'code': 0.30; 'certain': 0.31; 'fixed': 0.31; 'rule': 0.33; 'skip:j 20': 0.33; 'similar': 0.33; 'received:google.com': 0.35; 'next': 0.35; 'nov': 0.35; "isn't": 0.35; 'but': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'say': 0.37; 'received:209.85.213': 0.37; 'itself': 0.38; 'received:209': 0.38; 'names': 0.38; 'means': 0.39; 'some': 0.40; "you'll": 0.61; 'skip:u 10': 0.61; 'results': 0.66; 'direct': 0.68; 'special': 0.73; 'chrisa': 0.84; 'locals': 0.84; 'presumably': 0.84; 'saying:': 0.84; 'absolutely': 0.88; 'to:none': 0.91; 'inheritance,': 0.93; 'confirms': 0.95; '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=10R8IVYXSV9xeDtnsZyQpEPqpqb0fmiFgTH1JWozE60=; b=0Vzay4ZxCBYGRSVA/2ijW7slsv33VJOSsnBZHkNNPND4HVnSMPzjl3JNYAIZhGTIQX QiEQoSrkwdAoxAORdlRZ6iUA5yUvKURV2OaraN6yxQckQcJRQ1RJcGAK7oOaZojwFC3L 8WFCwVStT9IiVsRgrXFBildphQFVvNQ1X0hN5J6zL7g8mchBjofnP5m1/zm3piq2Bss+ mZDsqrkkkvDDaUhpJs2wHH6aMGe26S7ZvDIxG417/d3a7CFnvcadyNI0myHSi6hNBXZ7 j829kaXMn1c/O1aTJvm8+18duKRB4rRLvscLdZrz2zra4xyG7l0VG0wEsx1BUKbqTlpi G0lw== X-Received: by 10.50.155.33 with SMTP id vt1mr21178092igb.92.1447072614993; Mon, 09 Nov 2015 04:36:54 -0800 (PST) In-Reply-To: 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:98515 On Mon, Nov 9, 2015 at 11:22 PM, BartC wrote: > I tried this code: > > a=10 > print (a) > > del a > #print (a) > > a=20 > print (a) > > That sort of confirms what you are saying: that names don't even come into > existence until the first time they are encountered. They don't just contain > None, or some other value which means the name itself exists, but it hasn't > been initialised to anything. And that del removes the name completely from > the set that are known. > > That makes Python unlike any other language I've used. It's a direct consequence of the dynamic namespacing. You'll find similar results in JavaScript/ECMAScript if you play around with prototype-based inheritance, which has a similar rule ("if the property isn't here, look at the prototype") to the Python namespacing rule ("if the name isn't in this namespace, look at the next one outward"). And you're absolutely correct. Unused names do not "contain None" in any sense - they utterly do not exist. When you 'del' a name, that name utterly ceases to exist. > On the other hand, if I put the above code into a function and then call the > function, attempting to print a just after it's been deleted results in: > > UnboundLocalError: local variable 'a' referenced before assignment That's a special case of NameError that was added to make it a bit easier to track down certain types of bug. > So while local names can presumably be manipulated just like globals, that > doesn't stop being implemented via a fixed slot in a table. > Global names are simply module attributes, so they can be manipulated in many ways. Function locals are not; there's no way to say "current_stack_frame.foo = 2", so there's no need to hack around with name lookups. (The locals() dictionary isn't meant to be modified, and changes may or may not have effect on actual local name bindings.) ChrisA