Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #86215

Re: list storing variables

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.025
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'modify': 0.07; 'variables': 0.07; 'feature.': 0.09; 'language,': 0.12; 'changes': 0.15; '#this': 0.16; '[2,': 0.16; 'ast': 0.16; 'immutable,': 0.16; 'mutable': 0.16; 'share,': 0.16; 'simplest': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'header:User-Agent:1': 0.23; 'define': 0.26; 'pass': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'subject:list': 0.30; '>>>>': 0.31; 'about.': 0.31; 'container': 0.31; 'object.': 0.31; 'class': 0.32; 'could': 0.34; 'connection': 0.35; 'something': 0.35; 'there': 0.35; 'list': 0.37; 'list.': 0.37; 'expected': 0.38; 'to:addr :python-list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'affect': 0.61; 'impact': 0.61; "you're": 0.61; 'address': 0.63; 'charset:windows-1252': 0.65; 'within': 0.65; 'dont': 0.67; 'received:74.208': 0.68; 'fact,': 0.69; 'sides.': 0.84
Date Mon, 23 Feb 2015 08:24:02 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: list storing variables
References <54eb2357$0$3011$426a74cc@news.free.fr>
In-Reply-To <54eb2357$0$3011$426a74cc@news.free.fr>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:OigouutCNxDTaivlN/I4qqilNhr66AT/jEm6Ru166du 8g8SpXvXIGb42QlmhXeJV1NYEdlBN2zj6037GBUOFQax1PnUMy 9Ui6pvXC8qgQOT4kdU1qu1pVM3agwfj3HG1iRb9qP6emGjENTF lZ1J/Hk9x1vGxkDdirGZs4VbFfwKFv7Uw/6ldsoh/fUtqo4xjB BFhj1X1mRzEa6c3xtJ/+ewV/qazIb1s50cHZZfl5NH4AjL3AOE kZz9SnUs1b2r0fZikiglrjzKCeON4mHWVJd2fGWatRWnrTfTuY E4BrzJtcE2CZeKScgD7qTqPjxI1vr6ip/pklbn9mRA40/IQTEi VfO1PDA6ORQEToq2aLWc=
X-UI-Out-Filterresults notjunk:1;
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.19069.1424697860.18130.python-list@python.org> (permalink)
Lines 54
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424697860 news.xs4all.nl 2908 [2001:888:2000:d::a6]:42947
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86215

Show key headers only | View raw


On 02/23/2015 07:55 AM, ast wrote:
> hi
>
>>>> a = 2; b = 5
>>>> Li = [a, b]
>>>>
>>>> Li
> [2, 5]
>>>> a=3
>>>> Li
> [2, 5]
>>>>
>
> Ok, a change in a or b doesn't impact Li. This works as expected
>
> 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 ?
>
> I dont need this feature. It is just something I am thinking about.
>
> In C language, there is &A for address of A
>

When you do an "a=3"  you are rebinding a, and that has no connection to 
what's in the list.  If you were to modify the object that a and L1[0] 
share, then yes, the modifications would affect both sides.

However, an int is immutable, so you cannot directly do it.

The simplest approximation to what you're asking is to use a list within 
the list.

a = [42]; b = 65
L1 = [a, b]
a[0] = 99       #this doesn't rebind a, just changes the list
                 # object it is bound to
print(L1)

yields:
[[99], 65]

Clearly, instead of a list, you could use some other mutable object.  In 
fact, you could use something like:

class Dummy(object):
     pass

a = Dummy()
a.value = 12
...


-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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