Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16913
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.chainon-marquant.org!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <andrea.crotti.0@gmail.com> |
| 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; 'example:': 0.03; 'classes.': 0.05; 'pointer': 0.05; 'python': 0.08; '"a"': 0.09; 'url:enthought': 0.09; 'url:github': 0.09; 'weak': 0.09; 'float': 0.13; '"b"': 0.16; 'arrays,': 0.16; 'brand-new': 0.16; 'numpy': 0.16; 'subject:changes': 0.16; 'subject:variable': 0.16; 'traits': 0.16; 'url:traits': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'rewrite': 0.18; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'assigning': 0.23; 'dictionary': 0.23; 'cc:2**0': 0.24; 'creating': 0.25; 'code': 0.25; 'tried': 0.27; 'variable': 0.28; 'cc:addr:python.org': 0.29; 'error': 0.29; 'pm,': 0.29; 'arrays': 0.30; 'float.': 0.30; 'object.': 0.30; 'received:mail-bw0-f46.google.com': 0.30; 'reflected': 0.30; 'reflect': 0.31; 'values': 0.32; 'point,': 0.32; 'pure': 0.32; 'changes': 0.32; 'received:209.85.214': 0.32; 'message- id:@gmail.com': 0.33; 'header:User-Agent:1': 0.33; 'actually': 0.33; 'rather': 0.33; 'there': 0.33; 'but': 0.37; 'reference': 0.37; 'hello,': 0.37; 'received:google.com': 0.37; 'using': 0.38; 'received:10.0.0': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'created': 0.38; "it's": 0.40; 'received:209': 0.40; 'show': 0.67; '08:17': 0.84; 'subject:value': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=vuGKzYlygT/yyo6a7jR1SHXzVj1q5azHNK43CXYiEaE=; b=Y+xKWDe9KonDxP364v/5Mn03Shs+Hiaj2H3vGBqalHPYlJqdkePj55Ovclird+ZO5z UK92bVoKlve+/R5AHRTJR+EYjMzGXXMcMOsyEA8l+yK/kQzw3mE3e21ris/IrGhHmtEO xNtPQPgqMG9PLgl/FjTdudbL5beRp9F2jPrio= |
| Date | Fri, 09 Dec 2011 12:43:07 +0000 |
| From | Andrea Crotti <andrea.crotti.0@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111108 Thunderbird/8.0 |
| MIME-Version | 1.0 |
| To | Catherine Moroney <Catherine.M.Moroney@jpl.nasa.gov> |
| Subject | Re: tracking variable value changes |
| References | <jbr607$eer$1@news.jpl.nasa.gov> |
| In-Reply-To | <jbr607$eer$1@news.jpl.nasa.gov> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3470.1323434593.27778.python-list@python.org> (permalink) |
| Lines | 37 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1323434593 news.xs4all.nl 6857 [2001:888:2000:d::a6]:49875 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:16913 |
Show key headers only | View raw
On 12/08/2011 08:17 PM, Catherine Moroney wrote:
> Hello,
>
> Is there a way to create a C-style pointer in (pure) Python so the
> following code will reflect the changes to the variable "a" in the
> dictionary "x"?
>
> For example:
>
> >>> a = 1.0
> >>> b = 2.0
> >>> x = {"a":a, "b":b}
> >>> x
> {'a': 1.0, 'b': 2.0}
> >>> a = 100.0
> >>> x
> {'a': 1.0, 'b': 2.0} ## at this point, I would like the value
> ## associated with the "a" key to be 100.0
> ## rather than 1.0
>
> If I make "a" and "b" numpy arrays, then changes that I make to the
> values of a and b show up in the dictionary x.
>
> My understanding is that when I redefine the value of "a", that Python
> is creating a brand-new float with the value of 100.0, whereas when I
> use numpy arrays I am merely assigning a new value to the same object.
>
> Is there some way to rewrite the code above so the change of "a" from
> 1.0 to 100.0 is reflected in the dictionary. I would like to use
> simple datatypes such as floats, rather than numpy arrays or classes.
> I tried using weakref's, but got the error that a weak reference cannot
> be created to a float.
>
> Catherine
Not sure if it's exactly pure python but Traits can actually do this
https://github.com/enthought/traits
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
tracking variable value changes Catherine Moroney <Catherine.M.Moroney@jpl.nasa.gov> - 2011-12-08 12:17 -0800
Re: tracking variable value changes Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-08 14:50 -0700
Re: tracking variable value changes Ben Finney <ben+python@benfinney.id.au> - 2011-12-09 09:06 +1100
Re: tracking variable value changes Arnaud Delobelle <arnodel@gmail.com> - 2011-12-08 22:10 +0000
Re: tracking variable value changes Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-12-09 12:43 +0000
Re: tracking variable value changes alex23 <wuwei23@gmail.com> - 2011-12-11 21:45 -0800
Re: tracking variable value changes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-10 00:41 +0000
csiph-web