Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86271
| 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 | <python-python-list@m.gmane.org> |
| 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 <ben+python@benfinney.id.au> |
| 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 <bignose+hates-spam@benfinney.id.au> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19104.1424728988.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
"ast" <nomail@invalid.com> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
list storing variables "ast" <nomail@invalid.com> - 2015-02-23 13:55 +0100
Re: list storing variables Dave Angel <davea@davea.name> - 2015-02-23 08:24 -0500
Re: list storing variables Marko Rauhamaa <marko@pacujo.net> - 2015-02-23 15:49 +0200
Re: list storing variables Peter Pearson <pkpearson@nowhere.invalid> - 2015-02-23 17:35 +0000
Re: list storing variables Marko Rauhamaa <marko@pacujo.net> - 2015-02-23 20:22 +0200
Re: list storing variables Peter Otten <__peter__@web.de> - 2015-02-23 19:41 +0100
Re: list storing variables Marko Rauhamaa <marko@pacujo.net> - 2015-02-23 21:06 +0200
Re: list storing variables Chris Angelico <rosuav@gmail.com> - 2015-02-24 06:17 +1100
Re: list storing variables Marko Rauhamaa <marko@pacujo.net> - 2015-02-23 22:25 +0200
Re: list storing variables Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-23 12:29 -0700
Re: list storing variables Marko Rauhamaa <marko@pacujo.net> - 2015-02-23 22:38 +0200
Re: list storing variables Ben Finney <ben+python@benfinney.id.au> - 2015-02-24 09:03 +1100
Re: list storing variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-24 13:24 +1100
Re: list storing variables Marko Rauhamaa <marko@pacujo.net> - 2015-02-24 10:18 +0200
csiph-web