Path: csiph.com!usenet.pasdenom.info!news.albasani.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(at': 0.04; 'cpython': 0.05; 'binary': 0.07; 'level,': 0.07; 'memory.': 0.07; "'a'": 0.09; 'bits': 0.09; 'referenced': 0.09; 'structure,': 0.09; 'subject: [': 0.09; 'url:blog': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; "'b'": 0.16; "computer's": 0.16; 'internally': 0.16; 'reflects': 0.16; 'scopes': 0.16; 'skip:0 60': 0.16; 'subject:versus': 0.16; 'differ': 0.19; 'value.': 0.19; 'written': 0.21; 'machine': 0.22; '>>>': 0.22; 'memory': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'form:': 0.24; 'connected': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'post': 0.26; 'least': 0.26; 'somewhere': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'locations': 0.30; '(which': 0.31; 'explained': 0.31; 'keys': 0.31; 'url:category': 0.31; 'values.': 0.31; 'this.': 0.32; '(i.e.': 0.33; 'addresses': 0.33; 'implemented': 0.33; 'third': 0.33; 'actual': 0.34; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'addresses,': 0.36; 'explains': 0.36; 'charset:us-ascii': 0.36; 'virtual': 0.37; 'level': 0.37; 'how': 0.40; 'even': 0.60; 'read': 0.60; 'easy': 0.60; 'course': 0.61; 'first': 0.61; 'content- disposition:inline': 0.62; 'name': 0.63; 'more': 0.64; 'series': 0.66; 'detail.': 0.68; "how's": 0.74; 'subject:gets': 0.84; 'to:addr:support': 0.84; 'url:tech': 0.84; 'do:': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=EmQ+ejpitN9AYleQLtXl0wKKSfv88O1yLG7k1Uzn2JE=; b=cNsn/XsffnR6RE9r5TyAMlKOjN7izuWCFiR4leBXt1IZKPUDe3xCUSv3kVMmGSeQA5 5Rwezs7Dx39NQ6sHgDJC5vfyR1inbumlQAjfg7g4MRnnE8owWzMR1R4ii2UgWhe7lLks C1rVU/urIhCcQkt5BBmq+4rZGX8697Rcz2qw7vpexdybv1eY4DwDoSK6NYEGdJc35cQ+ QP5zFdK5McBhHb3/4sVlnjL52V7JOnEp6DUzZa9EXmUWVy1/ZxtvxKqdrNS/HhcXpqo7 Ulhgaopvj0I3m/sz+kmFJ6rtNKm+R+EBygWpN0k1CuGyWeQAtdLXIbF35kuL1Dc1BNxr giyg== X-Received: by 10.194.238.199 with SMTP id vm7mr9345996wjc.37.1371525735509; Mon, 17 Jun 2013 20:22:15 -0700 (PDT) Date: Tue, 18 Jun 2013 04:22:07 +0100 From: Marcin Szamotulski To: =?utf-8?B?zp3Or866zr/Pgg==?= Subject: Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] References: <51beb20c$0$29872$c3e8da3$5496439d@news.astraweb.com> <51bf9714$0$29872$c3e8da3$5496439d@news.astraweb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: python-list@python.org 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371525742 news.xs4all.nl 15903 [2001:888:2000:d::a6]:55414 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48592 > While you said to me to forget about memory locations, and that's indeed > made things easy to follow i still keep wondering, how Python internally > keeping tracks of 'x' and 'y' names as well as their referenced objects > (i.e. number 6). There is an excellent blog post about CPython internals: http://tech.blog.aknin.name/category/my-projects/pythons-innards/ but it might be difficult to follow if you cannot at least read C. It explains how python virtual machine works internally, how the opcodes are evaluated, how the three scopes globals, locals and builins find its place (and how names are bind). As far as I understand names are keys in the scope dictionaries, which are exposed in the python level as locals(), globals() and the builtin's. This is how Python tracks names and their values. To be more precise, when you do: >>> a = 1 >>> def f(): ... b=2 in the first line 'a' is added to the globals() dictionary with value 1, and in the third line 'b' with value 2 is added to the local dictionary of f. It is also all explained in the python docs, and it reflects how python is implemented (at least CPython). > > After all the way i understand memory is as a series of bits like: > > 0100010100011110101000010101010010001001010010011100001101001010010 > > So from the above binary form: > > what is 'x', what is 'y', how's 'x' and 'y' differ from the actually > memory locations that are bound too, and of course what is the actual value. 'x' and 'y' are just strings which are written somewhere in the computer's memory. > > Its 3 things for me to consider, even in Python id internal level > detail. I want to understand this. > > names, memory addresses, memory address's actual values Names and values are not connected through their memory addresses but because they live in a higher structure, name is a key and value is a value of a dictionary (which is also represented in some way at the C level, namely by PyDictObject ... but for this you need to first learn C, but please read and understand the Python docs - there is already a lot there for you ... Best regards, Marcin