Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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; 'python.': 0.02; 'value,': 0.04; 'argument': 0.05; 'explicitly': 0.05; 'variables': 0.07; 'logic': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'language,': 0.12; 'changes': 0.15; 'bindings.': 0.16; 'equal.': 0.16; 'finney': 0.16; 'objects.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'robust,': 0.16; 'stored.': 0.16; "{'a':": 0.16; 'variable': 0.18; 'pointed': 0.19; 'value.': 0.19; '>>>': 0.22; 'coding': 0.22; 'header:User- Agent:1': 0.23; '(such': 0.24; 'define': 0.26; 'references': 0.26; 'supported': 0.26; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'subject:list': 0.30; 'adams': 0.31; 'container': 0.31; 'writes:': 0.31; 'yourself.': 0.31; 'sense': 0.34; 'except': 0.35; 'no,': 0.35; 'there': 0.35; 'expected': 0.38; 'ben': 0.38; 'mapping': 0.38; 'to:addr:python-list': 0.38; 'track': 0.38; 'does': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'impact': 0.61; 'address': 0.63; 'name': 0.63; 'more': 0.64; 'different': 0.65; 'great': 0.65; 'skip:\xe2 10': 0.65; '8bit%:40': 0.68; 'containing': 0.69; 'opinions': 0.70; 'affected.': 0.84; 'collection.': 0.84; 'received:125': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: list storing variables Date: Tue, 24 Feb 2015 09:03:18 +1100 References: <54eb2357$0$3011$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:SoVKGtFBPQS7pT7l5BIL65Zd84Q= 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424728988 news.xs4all.nl 2935 [2001:888:2000:d::a6]:56606 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86271 "ast" writes: > Ok, a change in a or b doesn't impact Li. This works as expected Because a container stores references to objects. The other references (such as names) that object might have are not stored. > Is there a way to define a container object able to store some > variables so that a change of a variable make a change in this object > content ? As has been pointed out, Python does not have “variables” in the sense of a named box containing a value. What Python does have is a mapping type. You can store a key → value mapping for each value you want to reference later. >>> a = 2; b = 5 >>> foo = {'a': a, 'b': b} >>> foo {'b': 5, 'a': 2} >>> foo['a'] = 3 >>> foo {'b': 5, 'a': 3} You appear, though, to want this to somehow automatically track the changes in name bindings. No, there's no way to do that except explicitly coding it yourself. > In C language, there is &A for address of A There is no “address of a value” concept in Python. You access a value by some reference, either a name or an item in a collection. When a reference changes to reference some different value, other references are not affected. -- \ “All opinions are not equal. Some are a very great deal more | `\ robust, sophisticated, and well supported in logic and argument | _o__) than others.” —Douglas Adams | Ben Finney