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


Groups > comp.lang.python > #47884 > unrolled thread

Re: A certainl part of an if() structure never gets executed.

Started bySteven D'Aprano <steve+comp.lang.python@pearwood.info>
First post2013-06-13 01:55 +0000
Last post2013-06-14 10:05 +0100
Articles 20 on this page of 115 — 33 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: A certainl part of an if() structure never gets executed. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-13 01:55 +0000
    Re: A certainl part of an if() structure never gets executed. Chris Angelico <rosuav@gmail.com> - 2013-06-13 12:03 +1000
    Re: A certainl part of an if() structure never gets executed. Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2013-06-13 10:05 +0530
    Re: A certainl part of an if() structure never gets executed. Chris Angelico <rosuav@gmail.com> - 2013-06-13 14:39 +1000
    Re: A certainl part of an if() structure never gets executed. Νικόλαος Κούρας <support@superhost.gr> - 2013-06-13 08:36 +0300
    Re: A certainl part of an if() structure never gets executed. Νικόλαος Κούρας <support@superhost.gr> - 2013-06-13 10:11 +0300
      Re: A certainl part of an if() structure never gets executed. Sibylle Koczian <nulla.epistola@web.de> - 2013-06-13 14:22 +0200
        Re: A certainl part of an if() structure never gets executed. Νικόλαος Κούρας <support@superhost.gr> - 2013-06-13 17:26 +0300
          Re: A certainl part of an if() structure never gets executed. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-14 01:14 +0000
            Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-14 11:03 +0300
              Re: A certainl part of an if() structure never gets executed. Chris Angelico <rosuav@gmail.com> - 2013-06-14 18:23 +1000
              Re: A certainl part of an if() structure never gets executed. "R. Michael Weylandt" <michael.weylandt@gmail.com> - 2013-06-14 09:24 +0100
              Re: A certainl part of an if() structure never gets executed. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-06-14 11:28 +0300
                Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-14 11:41 +0300
                  Re: A certainl part of an if() structure never gets executed. Chris Angelico <rosuav@gmail.com> - 2013-06-14 18:50 +1000
                  Re: A certainl part of an if() structure never gets executed. Fábio Santos <fabiosantosart@gmail.com> - 2013-06-14 10:03 +0100
                  Re: A certainl part of an if() structure never gets executed. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-06-14 12:21 +0300
                    Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-14 12:44 +0300
                      Re: A certainl part of an if() structure never gets executed. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-06-14 15:40 +0300
                        Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-14 16:07 +0300
                          Re: A certainl part of an if() structure never gets executed. Zero Piraeus <schesis@gmail.com> - 2013-06-14 09:48 -0400
                            Re: A certainl part of an if() structure never gets executed. rusi <rustompmody@gmail.com> - 2013-06-14 07:05 -0700
                            Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-14 17:08 +0300
                          Re: A certainl part of an if() structure never gets executed. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-14 16:31 +0000
                            Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-14 19:56 +0300
                              Re: A certainl part of an if() structure never gets executed. Chris Angelico <rosuav@gmail.com> - 2013-06-15 03:18 +1000
                              Re: A certainl part of an if() structure never gets executed. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-06-14 21:17 +0300
                              Re: A certainl part of an if() structure never gets executed. Larry Hudson <orgnut@yahoo.com> - 2013-06-14 22:27 -0700
                                Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-15 11:39 +0300
                                  Re: A certainl part of an if() structure never gets executed. Lele Gaifax <lele@metapensiero.it> - 2013-06-15 11:54 +0200
                                    Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-15 16:07 +0300
                                      Re: A certainl part of an if() structure never gets executed. Michael Torrie <torriem@gmail.com> - 2013-06-15 09:53 -0600
                                        Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-15 19:18 +0300
                                          Re: A certainl part of an if() structure never gets executed. Michael Torrie <torriem@gmail.com> - 2013-06-15 11:45 -0600
                                          Re: A certainl part of an if() structure never gets executed. Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-16 06:32 +0000
                                            Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-16 11:07 +0300
                                              Re: A certainl part of an if() structure never gets executed. Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-16 09:22 +0000
                                                Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-16 12:59 +0300
                                                  Re: A certainl part of an if() structure never gets executed. "R. Michael Weylandt" <michael.weylandt@gmail.com> - 2013-06-16 11:42 +0100
                                                    Re: A certainl part of an if() structure never gets executed. Ferrous Cranus <support@superhost.gr> - 2013-06-16 14:06 +0300
                                                      Re: A certainl part of an if() structure never gets executed. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-16 12:26 +0100
                                                      Re: A certainl part of an if() structure never gets executed. YBM <ybmess@nooos.fr.invalid> - 2013-06-16 14:00 +0200
                                                      Re: A certainl part of an if() structure never gets executed. "R. Michael Weylandt" <michael.weylandt@gmail.com> - 2013-06-16 13:04 +0100
                                                        Re: A certainl part of an if() structure never gets executed. Ferrous Cranus <support@superhost.gr> - 2013-06-16 16:38 +0300
                                                          Re: A certainl part of an if() structure never gets executed. "R. Michael Weylandt" <michael.weylandt@gmail.com> - 2013-06-16 19:50 +0100
                                                  Re: A certainl part of an if() structure never gets executed. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-16 11:52 +0100
                                                  Re: A certainl part of an if() structure never gets executed. Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-16 10:51 +0000
                                                    Compiling vs interpreting [was Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-16 12:07 +0000
                                                      Re: Compiling vs interpreting [was Re: A certainl part of an if() structure never gets executed.] Mark Janssen <dreamingforward@gmail.com> - 2013-06-16 12:31 -0700
                                                        Re: Compiling vs interpreting [was Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-16 20:02 +0000
                                                          Re: Compiling vs interpreting [was Re: A certainl part of an if() structure never gets executed.] Chris Angelico <rosuav@gmail.com> - 2013-06-17 08:26 +1000
                                                      Re: Compiling vs interpreting [was Re: A certainl part of an if() structure never gets executed.] Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-16 23:13 -0400
                                                  Re: A certainl part of an if() structure never gets executed. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-06-16 14:13 +0300
                                                    Re: A certainl part of an if() structure never gets executed. Ferrous Cranus <support@superhost.gr> - 2013-06-16 16:47 +0300
                                                      Re: A certainl part of an if() structure never gets executed. "R. Michael Weylandt" <michael.weylandt@gmail.com> - 2013-06-16 19:53 +0100
                                                        Re: A certainl part of an if() structure never gets executed. Νίκος <support@superhost.gr> - 2013-06-17 08:17 +0300
                                                          Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-17 06:51 +0000
                                                            Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Simpleton <support@superhost.gr> - 2013-06-17 14:34 +0300
                                                              Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Michael Torrie <torriem@gmail.com> - 2013-06-17 05:58 -0600
                                                                Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Simpleton <support@superhost.gr> - 2013-06-17 18:50 +0300
                                                                  Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Larry Hudson <orgnut@yahoo.com> - 2013-06-17 23:39 -0700
                                                                    Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-18 07:24 +0000
                                                                    Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Νίκος <support@superhost.gr> - 2013-06-18 11:49 +0300
                                                                      Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-18 09:05 +0000
                                                                        Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Νίκος <support@superhost.gr> - 2013-06-18 12:51 +0300
                                                                          Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Chris Angelico <rosuav@gmail.com> - 2013-06-18 20:22 +1000
                                                                          Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Michael Torrie <torriem@gmail.com> - 2013-06-19 23:16 -0600
                                                                            Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-20 05:48 +0000
                                                                              Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Michael Torrie <torriem@gmail.com> - 2013-06-20 00:01 -0600
                                                                                Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] 88888 Dihedral <dihedral88888@gmail.com> - 2013-06-26 01:18 -0700
                                                                          Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Michael Torrie <torriem@gmail.com> - 2013-06-19 23:44 -0600
                                                                          Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Roel Schroeven <roel@roelschroeven.net> - 2013-06-20 19:19 +0200
                                                              Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Terry Reedy <tjreedy@udel.edu> - 2013-06-17 10:22 -0400
                                                                Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Simpleton <support@superhost.gr> - 2013-06-17 18:55 +0300
                                                                  Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Joel Goldstick <joel.goldstick@gmail.com> - 2013-06-17 12:26 -0400
                                                                  Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Benjamin Kaplan <benjamin.kaplan@case.edu> - 2013-06-17 09:23 -0700
                                                                    Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Νίκος <support@superhost.gr> - 2013-06-17 20:17 +0300
                                                                      Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Terry Reedy <tjreedy@udel.edu> - 2013-06-17 18:16 -0400
                                                              Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-17 23:09 +0000
                                                                Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Νίκος <support@superhost.gr> - 2013-06-18 02:26 +0300
                                                                  Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-18 00:41 +0000
                                                                    Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Dave Angel <davea@davea.name> - 2013-06-17 21:06 -0400
                                                                      Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-18 02:42 +0000
                                                                        Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Dave Angel <davea@davea.name> - 2013-06-18 00:12 -0400
                                                                          Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-18 06:04 +0000
                                                                    Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-18 02:38 +0000
                                                                      Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-18 02:46 +0000
                                                                  Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-17 21:34 -0400
                                                                  Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.] Marcin Szamotulski <mszamot@gmail.com> - 2013-06-18 04:22 +0100
                                                          Re: A certainl part of an if() structure never gets executed. Michael Weylandt <michael.weylandt@gmail.com> - 2013-06-17 07:56 +0100
                                                Re: A certainl part of an if() structure never gets executed. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-16 12:50 +0000
                                            OT: C vs Python terminology (was: A certainl part of an if() structure never gets executed) Andreas Perstinger <andipersti@gmail.com> - 2013-06-16 13:22 +0200
                                            Re: OT: C vs Python terminology Dave Angel <davea@davea.name> - 2013-06-16 08:55 -0400
                                            Re: OT: C vs Python terminology Andreas Perstinger <andipersti@gmail.com> - 2013-06-16 17:02 +0200
                                            Re: OT: C vs Python terminology Dave Angel <davea@davea.name> - 2013-06-16 21:58 -0400
              Re: A certainl part of an if() structure never gets executed. "R. Michael Weylandt" <michael.weylandt@gmail.com> - 2013-06-14 09:28 +0100
              Re: A certainl part of an if() structure never gets executed. Fábio Santos <fabiosantosart@gmail.com> - 2013-06-14 09:35 +0100
              Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-14 11:44 +0300
                Re: A certainl part of an if() structure never gets executed. Chris Angelico <rosuav@gmail.com> - 2013-06-14 18:57 +1000
                  Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-14 12:00 +0300
                    Re: A certainl part of an if() structure never gets executed. Chris Angelico <rosuav@gmail.com> - 2013-06-14 19:12 +1000
                      Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-14 12:47 +0300
                        Re: A certainl part of an if() structure never gets executed. Tim Roberts <timr@probo.com> - 2013-06-15 18:55 -0700
                          Re: A certainl part of an if() structure never gets executed. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-16 05:09 +0000
                          Re: A certainl part of an if() structure never gets executed. Nick the Gr33k <support@superhost.gr> - 2013-06-16 11:20 +0300
                            Re: A certainl part of an if() structure never gets executed. Tim Roberts <timr@probo.com> - 2013-06-18 22:08 -0700
                              Re: A certainl part of an if() structure never gets executed. Dave Angel <davea@davea.name> - 2013-06-19 01:42 -0400
                              Re: A certainl part of an if() structure never gets executed. Chris Angelico <rosuav@gmail.com> - 2013-06-19 17:14 +1000
                              Re: A certainl part of an if() structure never gets executed. Νίκος <support@superhost.gr> - 2013-06-19 10:49 +0300
                              Re: A certainl part of an if() structure never gets executed. Dave Angel <davea@davea.name> - 2013-06-19 04:06 -0400
                              Re: A certainl part of an if() structure never gets executed. Chris Angelico <rosuav@gmail.com> - 2013-06-19 18:21 +1000
                                Re: A certainl part of an if() structure never gets executed. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-19 08:55 +0000
                                  Re: A certainl part of an if() structure never gets executed. Chris Angelico <rosuav@gmail.com> - 2013-06-19 19:14 +1000
                    Re: A certainl part of an if() structure never gets executed. Grant Edwards <invalid@invalid.invalid> - 2013-06-14 14:38 +0000
                Re: A certainl part of an if() structure never gets executed. Fábio Santos <fabiosantosart@gmail.com> - 2013-06-14 10:05 +0100

Page 4 of 6 — ← Prev page 1 2 3 [4] 5 6  Next page →


#48600 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromLarry Hudson <orgnut@yahoo.com>
Date2013-06-17 23:39 -0700
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<HdmdncUNJIsSnV3MnZ2dnUVZ_oGdnZ2d@giganews.com>
In reply to#48526
On 06/17/2013 08:50 AM, Simpleton wrote:
> On 17/6/2013 2:58 μμ, Michael Torrie wrote:
>
> a = 5
> b = a
>
> a <---> memory address
> b <---> memory address
>
> I like to think a and b as references to the same memory address
>
Not quite:  a and b _are_ memory addresses,  At the same time, a and b are references to the 
data (the objects) stored in those memory locations.

The distinction is probably more important in languages like C/C++, where the _language_ gives 
you direct access to, and can manipulate, these memory addresses (through pointers).  Python 
handles it differently and does not give you this sort of ability, it all occurs "under the 
hood".  Yes, the id() function will tell you the addresses, but you can't do anything with them 
other than perhaps compare them.  It's really pretty much useless information.

[toc] | [prev] | [next] | [standalone]


#48604 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-06-18 07:24 +0000
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<51c00b28$0$29872$c3e8da3$5496439d@news.astraweb.com>
In reply to#48600
On Mon, 17 Jun 2013 23:39:10 -0700, Larry Hudson wrote:

> On 06/17/2013 08:50 AM, Simpleton wrote:
>> On 17/6/2013 2:58 μμ, Michael Torrie wrote:
>>
>> a = 5
>> b = a
>>
>> a <---> memory address
>> b <---> memory address
>>
>> I like to think a and b as references to the same memory address
>>
> Not quite:  a and b _are_ memory addresses,  

Not in Python they aren't. a and b are names in a namespace.


> At the same time, a and b
> are references to the data (the objects) stored in those memory
> locations.

Not in Python they aren't. In Python, objects are free to move around 
memory. Not all implementations take advantage of this freedom, but some 
like Jython, IronPython and PyPy do.


> The distinction is probably more important in languages like C/C++,
> where the _language_ gives you direct access to, and can manipulate,
> these memory addresses (through pointers).  Python handles it
> differently and does not give you this sort of ability, it all occurs
> "under the hood".  Yes, the id() function will tell you the addresses,
> but you can't do anything with them other than perhaps compare them. 
> It's really pretty much useless information.

The id() function does not tell you the address of the object, except by 
accident. The id() function gives you an arbitrary ID number for the 
object:


steve@runes:~$ ipy
IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433
Type "help", "copyright", "credits" or "license" for more information.
>>> id([])
43
>>> id('*')
44


steve@runes:~$ jython
Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19) 
[OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18
Type "help", "copyright", "credits" or "license" for more information.
>>> id([])
1
>>> id('*')
2



That some implementations happen to use a fixed memory address as the ID 
number is, well, a mere accident of implementation. That's not what id() 
*is*, any more than "id() returns the next value in an integer sequence 
starting from 43" just because that's what IronPython happens to do.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#48609 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromΝίκος <support@superhost.gr>
Date2013-06-18 11:49 +0300
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<kpp6v1$le7$1@news.grnet.gr>
In reply to#48600
Στις 18/6/2013 9:39 πμ, ο/η Larry Hudson έγραψε:
> Not quite:  a and b _are_ memory addresses,  At the same time, a and b
> are references to the data (the objects) stored in those memory locations.
>
> The distinction is probably more important in languages like C/C++,
> where the _language_ gives you direct access to, and can manipulate,
> these memory addresses (through pointers).  Python handles it
> differently and does not give you this sort of ability, it all occurs
> "under the hood".  Yes, the id() function will tell you the addresses,
> but you can't do anything with them other than perhaps compare them.
> It's really pretty much useless information.

So, a and b are actual memory addresses.

Does the term of a pointer exist in Python?
I mean if print(a) or print(b) outputs the object that a and b are 
linked to, then how do we access a's and b's memory locations themselves 
t create links among variables, one pointing to the other and so on?

Can a variable point to another variable or variables never point to 
other variables but instead are *only* linked to the objects of those 
var's instead?


-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48612 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-06-18 09:05 +0000
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<51c022d5$0$29872$c3e8da3$5496439d@news.astraweb.com>
In reply to#48609
On Tue, 18 Jun 2013 11:49:36 +0300, Νίκος wrote:

> Στις 18/6/2013 9:39 πμ, ο/η Larry Hudson έγραψε:
>> Not quite:  a and b _are_ memory addresses,  At the same time, a and b
>> are references to the data (the objects) stored in those memory
>> locations.
>>
>> The distinction is probably more important in languages like C/C++,
>> where the _language_ gives you direct access to, and can manipulate,
>> these memory addresses (through pointers).  Python handles it
>> differently and does not give you this sort of ability, it all occurs
>> "under the hood".  Yes, the id() function will tell you the addresses,
>> but you can't do anything with them other than perhaps compare them.
>> It's really pretty much useless information.
> 
> So, a and b are actual memory addresses.

No, no, no, a thousand times no.


> Does the term of a pointer exist in Python? 

No.


> I mean if print(a) or
> print(b) outputs the object that a and b are linked to, then how do we
> access a's and b's memory locations themselves t create links among
> variables, one pointing to the other and so on?

You cannot. You can only have links between OBJECTS, not between 
VARIABLES. There is no way to have a name "a" set to point to another 
name "b". All you can do is have a name "a" set to refer to the same 
object as "b" has *right now*. If "b" changes to another object, "a" will 
not follow.


> Can a variable point to another variable or variables never point to
> other variables but instead are *only* linked to the objects of those
> var's instead?

Names are *always* linked to objects, not to other names.

a = []
b = a  # Now a and b refer to the same list
a = {} # Now a refers to a dict, and b refers to the same list as before




-- 
Steven

[toc] | [prev] | [next] | [standalone]


#48615 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromΝίκος <support@superhost.gr>
Date2013-06-18 12:51 +0300
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<kppaih$jso$1@news.grnet.gr>
In reply to#48612
Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε:
> Names are *always* linked to objects, not to other names.
>
> a = []
> b = a  # Now a and b refer to the same list
> a = {} # Now a refers to a dict, and b refers to the same list as before

I see, thank you Steven.

But since this is a fact how do you create complicated data structures 
that rely on various variables pointing one to another liek we did in 
C++(cannot recall their names) ?

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48617 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromChris Angelico <rosuav@gmail.com>
Date2013-06-18 20:22 +1000
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<mailman.3523.1371550941.3114.python-list@python.org>
In reply to#48615
On Tue, Jun 18, 2013 at 7:51 PM, Νίκος <support@superhost.gr> wrote:
> Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε:
>
>> Names are *always* linked to objects, not to other names.
>>
>> a = []
>> b = a  # Now a and b refer to the same list
>> a = {} # Now a refers to a dict, and b refers to the same list as before
>
>
> I see, thank you Steven.
>
> But since this is a fact how do you create complicated data structures that
> rely on various variables pointing one to another liek we did in C++(cannot
> recall their names) ?

Why do you need to? Linked lists, trees, and so on are just tools.
They're usually used to implement data structures like mappings,
growable arrays, lists that can have elements inserted into them, etc,
etc. Python does these sorts of things in better ways. You should not
need to worry about memory locations, pointers, etc. Now, if you want
to have one object reference another, that can be done in plenty of
ways. Check the Python tutorial.

ChrisA

[toc] | [prev] | [next] | [standalone]


#48773 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromMichael Torrie <torriem@gmail.com>
Date2013-06-19 23:16 -0600
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<mailman.3608.1371706547.3114.python-list@python.org>
In reply to#48615
On 06/18/2013 03:51 AM, Νίκος wrote:
> Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε:
>> Names are *always* linked to objects, not to other names.
>>
>> a = []
>> b = a  # Now a and b refer to the same list
>> a = {} # Now a refers to a dict, and b refers to the same list as before
> 
> I see, thank you Steven.
> 
> But since this is a fact how do you create complicated data structures 
> that rely on various variables pointing one to another liek we did in 
> C++(cannot recall their names) ?
> 

As Steve said Python provides all manner of data structures and the
means to create data structures.  Any data structure (trees, lists, etc)
can all be made easily in Python using Python's basic data structures,
if the built-in data structures are not sufficient.  It turns out that
lists, hashes (dicts), and classes can pretty much do anything with
having to much about with C-style pointers and such.

Do yourself a favor and forget about the low-level stuff in Python for
now.  You'll be more frustrated if you don't.

The real power and expressivity of Python comes from embracing the
abstractions that Python provides to your advantage.  There's a certain
elegance and beauty that comes from such things, which I believe really
comes from the elegance and beauty of LISP, some of which manages to
shine forth in Python, despite its deficiencies.  When I first learned
Python, I was impressed that some of the elegance that I remember from
Scheme (how to use lists as a basic type for example) was there, but in
a form that appealed to me.

[toc] | [prev] | [next] | [standalone]


#48775 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-06-20 05:48 +0000
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<51c297a3$0$29973$c3e8da3$5496439d@news.astraweb.com>
In reply to#48773
On Wed, 19 Jun 2013 23:16:51 -0600, Michael Torrie wrote:

> The real power and expressivity of Python comes from embracing the
> abstractions that Python provides to your advantage.  There's a certain
> elegance and beauty that comes from such things, which I believe really
> comes from the elegance and beauty of LISP, some of which manages to
> shine forth in Python, despite its deficiencies.  When I first learned
> Python, I was impressed that some of the elegance that I remember from
> Scheme (how to use lists as a basic type for example) was there, but in
> a form that appealed to me.


Well said!


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#48776 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromMichael Torrie <torriem@gmail.com>
Date2013-06-20 00:01 -0600
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<mailman.3610.1371708078.3114.python-list@python.org>
In reply to#48775
On 06/19/2013 11:48 PM, Steven D'Aprano wrote:
> On Wed, 19 Jun 2013 23:16:51 -0600, Michael Torrie wrote:
> 
>> The real power and expressivity of Python comes from embracing the
>> abstractions that Python provides to your advantage.  There's a certain
>> elegance and beauty that comes from such things, which I believe really
>> comes from the elegance and beauty of LISP, some of which manages to
>> shine forth in Python, despite its deficiencies.  When I first learned
>> Python, I was impressed that some of the elegance that I remember from
>> Scheme (how to use lists as a basic type for example) was there, but in
>> a form that appealed to me.
> 
> 
> Well said!

Glad you made sense of it... the bit about LISP and Scheme came out a
wee bit muddled.  In fact thinking about it, perhaps LISPers would say
about Python what a bible passage says about having the form of
Godliness but denying the power thereof!  For example, Python's lambda
functions, and Python's functional programming capabilities in general.
 But since the LISP never really got a form beyond S-expressions,
leaving us with lots of parenthesis everywhere, Python wins much as the
Hitchhiker's Guide to the Galaxy wins.

[toc] | [prev] | [next] | [standalone]


#49233 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

From88888 Dihedral <dihedral88888@gmail.com>
Date2013-06-26 01:18 -0700
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<46a7a964-3bca-4805-9dd4-afe86d5c444c@googlegroups.com>
In reply to#48776
Michael Torrie於 2013年6月20日星期四UTC+8下午2時01分11秒寫道:
> 
>  But since the LISP never really got a form beyond S-expressions,
> 
> leaving us with lots of parenthesis everywhere, Python wins much as the
> 
> Hitchhiker's Guide to the Galaxy wins.

Yep, a list is mutable even it's empty.
But constant integers, floats, strings, and None is immutable.

The  variables in a function of python with default 
parameters which could be mutable or immutable.

def fun1( x, alist=[]):
    alist.append(x*x)
    return alist   ## valid

def fun2(x, alist=None):
    if alist==None: alist=[]
    alist.append(x*x)    
    return alist

# kind of boring to show the name binding mechanism of objects
# in Python in different usages
 



[toc] | [prev] | [next] | [standalone]


#48774 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromMichael Torrie <torriem@gmail.com>
Date2013-06-19 23:44 -0600
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<mailman.3609.1371707070.3114.python-list@python.org>
In reply to#48615
On 06/19/2013 11:16 PM, Michael Torrie wrote:
> It turns out that lists, hashes (dicts), and classes can pretty much
> do anything with having to much about with C-style pointers and
> such.

Oh wow. Parse error.  should read, "pretty much do anything without
having to muck about with C-style pointers and such."

[toc] | [prev] | [next] | [standalone]


#48812 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromRoel Schroeven <roel@roelschroeven.net>
Date2013-06-20 19:19 +0200
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<mailman.3634.1371748820.3114.python-list@python.org>
In reply to#48615
Νίκος schreef:
> Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε:
>> Names are *always* linked to objects, not to other names.
>>
>> a = []
>> b = a  # Now a and b refer to the same list
>> a = {} # Now a refers to a dict, and b refers to the same list as before
> 
> I see, thank you Steven.
> 
> But since this is a fact how do you create complicated data structures 
> that rely on various variables pointing one to another liek we did in 
> C++(cannot recall their names) ?

You almost never need to do that in Python. But if you really want to, 
out of curiosity, you can. For example, you could create a simple singly 
linked list like this:

 >>> class Node(object):
	def __init__(self, value):
		self.value = value
		self.next = None

		
 >>> first = Node(1)
 >>> second = Node(2)
 >>> first.next = second

You could iterate over it like this:

 >>> def iterate_linked_list(node):
	while node:
		yield node.value
		node = node.next

		
 >>> for v in iterate_linked_list(first):
	print v


-- 
"People almost invariably arrive at their beliefs not on the basis of
proof but on the basis of what they find attractive."
         -- Pascal Blaise

roel@roelschroeven.net

[toc] | [prev] | [next] | [standalone]


#48518 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromTerry Reedy <tjreedy@udel.edu>
Date2013-06-17 10:22 -0400
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<mailman.3481.1371478980.3114.python-list@python.org>
In reply to#48514
On 6/17/2013 7:34 AM, Simpleton wrote:
> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
>> Now, in languages like Python, Ruby, Java, and many others, there is no
>> table of memory addresses. Instead, there is a namespace, which is an
>> association between some name and some value:
>>
>> global namespace:
>>      x --> 23
>>      y --> "hello world"
>
> First of all thanks for the excellent and detailed explanation Steven.
>
> As for namespace:
>
> a = 5
>
> 1. a is associated to some memory location
> 2. the latter holds value 5

This is backwards. If the interpreter puts 5 in a *permanent* 'memory 
location' (which is not required by the language!), then it can 
associate 'a' with 5 by associating it with the memory location. CPython 
does this, but some other computer implementations do not.

> So 'a', is a reference to that memory location, so its more like a name
> to that memory location, yes? Instead of accessing a memory address with
> a use of an integer like "14858485995" we use 'a' instead.
>
> So is it safe to say that in Python a == &a ? (& stands for memory address)
>
> is the above correct?

When you interpret Python code, do you put data in locations with 
integer addresses?

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#48528 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromSimpleton <support@superhost.gr>
Date2013-06-17 18:55 +0300
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<kpnbhp$k63$2@news.ntua.gr>
In reply to#48518
On 17/6/2013 5:22 μμ, Terry Reedy wrote:
> On 6/17/2013 7:34 AM, Simpleton wrote:
>> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
>>> Now, in languages like Python, Ruby, Java, and many others, there is no
>>> table of memory addresses. Instead, there is a namespace, which is an
>>> association between some name and some value:
>>>
>>> global namespace:
>>>      x --> 23
>>>      y --> "hello world"
>>
>> First of all thanks for the excellent and detailed explanation Steven.
>>
>> As for namespace:
>>
>> a = 5
>>
>> 1. a is associated to some memory location
>> 2. the latter holds value 5
>
> This is backwards. If the interpreter puts 5 in a *permanent* 'memory
> location' (which is not required by the language!), then it can
> associate 'a' with 5 by associating it with the memory location. CPython
> does this, but some other computer implementations do not.

Please tell me how do i need to understand the sentence
'a' is being associated with number 5 in detail.

Why don't we access the desired value we want to, by referencing to that 
value's memory location directly instead of using namespaces wich is an 
indirect call?

i feel we have 3 things here

a , memory address of a stored value, actual stored value

>> So is it safe to say that in Python a == &a ? (& stands for memory
>> address)
>>
>> is the above correct?
>
> When you interpret Python code, do you put data in locations with
> integer addresses?

I lost you here.


-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48532 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-06-17 12:26 -0400
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<mailman.3487.1371486406.3114.python-list@python.org>
In reply to#48528

[Multipart message — attachments visible in raw view] — view raw

On Mon, Jun 17, 2013 at 11:55 AM, Simpleton <support@superhost.gr> wrote:

> On 17/6/2013 5:22 μμ, Terry Reedy wrote:
>
>> On 6/17/2013 7:34 AM, Simpleton wrote:
>>
>>> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
>>>
>>>> Now, in languages like Python, Ruby, Java, and many others, there is no
>>>> table of memory addresses. Instead, there is a namespace, which is an
>>>> association between some name and some value:
>>>>
>>>> global namespace:
>>>>      x --> 23
>>>>      y --> "hello world"
>>>>
>>>
>>> First of all thanks for the excellent and detailed explanation Steven.
>>>
>>> As for namespace:
>>>
>>> a = 5
>>>
>>> 1. a is associated to some memory location
>>> 2. the latter holds value 5
>>>
>>
>> This is backwards. If the interpreter puts 5 in a *permanent* 'memory
>> location' (which is not required by the language!), then it can
>> associate 'a' with 5 by associating it with the memory location. CPython
>> does this, but some other computer implementations do not.
>>
>
> Please tell me how do i need to understand the sentence
> 'a' is being associated with number 5 in detail.
>
> Why don't we access the desired value we want to, by referencing to that
> value's memory location directly instead of using namespaces wich is an
> indirect call?
>
> i feel we have 3 things here
>
> a , memory address of a stored value, actual stored value
>
>  So is it safe to say that in Python a == &a ? (& stands for memory
>>> address)
>>>
>>> is the above correct?
>>>
>>
>> When you interpret Python code, do you put data in locations with
>> integer addresses?
>>
>
> I lost you here.
>
>
>
> --
> What is now proved was at first only imagined!
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>


Read and study this.  Then come back and ask again.  Don't think of
physical representation of memory with actual binary addresses.  Python is
not assembler.  Neither is it C (sometimes called high level assembler)
http://docs.python.org/2/tutorial/classes.html#python-scopes-and-namespaces

-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#48533 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromBenjamin Kaplan <benjamin.kaplan@case.edu>
Date2013-06-17 09:23 -0700
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<mailman.3488.1371486574.3114.python-list@python.org>
In reply to#48528
On Mon, Jun 17, 2013 at 8:55 AM, Simpleton <support@superhost.gr> wrote:
> On 17/6/2013 5:22 μμ, Terry Reedy wrote:
>>
>> On 6/17/2013 7:34 AM, Simpleton wrote:
>>>
>>> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
>>>>
>>>> Now, in languages like Python, Ruby, Java, and many others, there is no
>>>> table of memory addresses. Instead, there is a namespace, which is an
>>>> association between some name and some value:
>>>>
>>>> global namespace:
>>>>      x --> 23
>>>>      y --> "hello world"
>>>
>>>
>>> First of all thanks for the excellent and detailed explanation Steven.
>>>
>>> As for namespace:
>>>
>>> a = 5
>>>
>>> 1. a is associated to some memory location
>>> 2. the latter holds value 5
>>
>>
>> This is backwards. If the interpreter puts 5 in a *permanent* 'memory
>> location' (which is not required by the language!), then it can
>> associate 'a' with 5 by associating it with the memory location. CPython
>> does this, but some other computer implementations do not.
>
>
> Please tell me how do i need to understand the sentence
> 'a' is being associated with number 5 in detail.
>
> Why don't we access the desired value we want to, by referencing to that
> value's memory location directly instead of using namespaces wich is an
> indirect call?
>
> i feel we have 3 things here
>
> a , memory address of a stored value, actual stored value
>
>>> So is it safe to say that in Python a == &a ? (& stands for memory
>>> address)
>>>
>>> is the above correct?
>>
>>
>> When you interpret Python code, do you put data in locations with
>> integer addresses?
>
>
> I lost you here.
>

You're confusing the way in which the CPython interpreter is written
with the way the Python language is defined. Yes, the CPython
interpreter puts 5 into a numbered memory location when creating the
object. But the Nikos Python Interpreter (which is a completely valid,
although quite buggy, Python interpreter that uses your head to
interpret the code) should not be using numbered memory locations.

Forget about memory locations. Memory locations don't exist. Let's use
the pen-and-paper Python interpreter. On the left side of the paper,
we'll write down the names. On the rest of the paper, we'll write down
the objects.

When I do "x =[]", I make a new list (which means I write down []
somewhere in the middle of the page), I create the name "x" (which
means I write down an "x" on the left side of the page), and then I
draw an arrow pointing from the x to the [].
(sorry if my drawing doesn't line up in your email/news client- I'll
try to make it line up correctly with a monospace font)
--------------------------------------------
|  x --------------> []                    |
|                                          |
|                                          |
--------------------------------------------

Now, When we do y = x, the right side of the equation is evaluated
(which gives us the object currently bound to the name x) and it is
then given the newly created name "y"
--------------------------------------------
|  x --------------> []                    |
|                     ^                    |
|   y ----------------|                    |
--------------------------------------------

When we do x.append(3), the object that x refers to is modified. This
is seen by both x and y because they point to the same object.

--------------------------------------------
|  x --------------> [3]                   |
|                     ^                    |
|   y ----------------|                    |
--------------------------------------------

When I do x = [], a new object is created somewhere else on the page,
and the name x is made to point to the new object. This changes the
arrow. The name "x" is not in any way tied to the location of the [3]
on the page. This doesn't impact "y" which is still pointing at the
same spot it was before

--------------------------------------------
|  x -------->[]     [3]                   |
|                     ^                    |
|   y ----------------|                    |
--------------------------------------------

That is how Python's object model works. In CPython, objects have
specified memory locations but names do not. In IronPython and Jython,
even that's not guaranteed- the garbage collector can move the objects
around during their lifetime, so while you can trust that a name will
always point to the correct object, you have no guarantee about where
the object is located in the computer's memory.

[toc] | [prev] | [next] | [standalone]


#48540 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromΝίκος <support@superhost.gr>
Date2013-06-17 20:17 +0300
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<kpngc1$av7$1@news.grnet.gr>
In reply to#48533
On 17/6/2013 7:23 μμ, Benjamin Kaplan wrote:
> On Mon, Jun 17, 2013 at 8:55 AM, Simpleton <support@superhost.gr> wrote:
>> On 17/6/2013 5:22 μμ, Terry Reedy wrote:
>>>
>>> On 6/17/2013 7:34 AM, Simpleton wrote:
>>>>
>>>> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
>>>>>
>>>>> Now, in languages like Python, Ruby, Java, and many others, there is no
>>>>> table of memory addresses. Instead, there is a namespace, which is an
>>>>> association between some name and some value:
>>>>>
>>>>> global namespace:
>>>>>       x --> 23
>>>>>       y --> "hello world"
>>>>
>>>>
>>>> First of all thanks for the excellent and detailed explanation Steven.
>>>>
>>>> As for namespace:
>>>>
>>>> a = 5
>>>>
>>>> 1. a is associated to some memory location
>>>> 2. the latter holds value 5
>>>
>>>
>>> This is backwards. If the interpreter puts 5 in a *permanent* 'memory
>>> location' (which is not required by the language!), then it can
>>> associate 'a' with 5 by associating it with the memory location. CPython
>>> does this, but some other computer implementations do not.
>>
>>
>> Please tell me how do i need to understand the sentence
>> 'a' is being associated with number 5 in detail.
>>
>> Why don't we access the desired value we want to, by referencing to that
>> value's memory location directly instead of using namespaces wich is an
>> indirect call?
>>
>> i feel we have 3 things here
>>
>> a , memory address of a stored value, actual stored value
>>
>>>> So is it safe to say that in Python a == &a ? (& stands for memory
>>>> address)
>>>>
>>>> is the above correct?
>>>
>>>
>>> When you interpret Python code, do you put data in locations with
>>> integer addresses?
>>
>>
>> I lost you here.
>>
>
> You're confusing the way in which the CPython interpreter is written
> with the way the Python language is defined. Yes, the CPython
> interpreter puts 5 into a numbered memory location when creating the
> object. But the Nikos Python Interpreter (which is a completely valid,
> although quite buggy, Python interpreter that uses your head to
> interpret the code) should not be using numbered memory locations.
>
> Forget about memory locations. Memory locations don't exist. Let's use
> the pen-and-paper Python interpreter. On the left side of the paper,
> we'll write down the names. On the rest of the paper, we'll write down
> the objects.
>
> When I do "x =[]", I make a new list (which means I write down []
> somewhere in the middle of the page), I create the name "x" (which
> means I write down an "x" on the left side of the page), and then I
> draw an arrow pointing from the x to the [].
> (sorry if my drawing doesn't line up in your email/news client- I'll
> try to make it line up correctly with a monospace font)
> --------------------------------------------
> |  x --------------> []                    |
> |                                          |
> |                                          |
> --------------------------------------------
>
> Now, When we do y = x, the right side of the equation is evaluated
> (which gives us the object currently bound to the name x) and it is
> then given the newly created name "y"
> --------------------------------------------
> |  x --------------> []                    |
> |                     ^                    |
> |   y ----------------|                    |
> --------------------------------------------
>
> When we do x.append(3), the object that x refers to is modified. This
> is seen by both x and y because they point to the same object.
>
> --------------------------------------------
> |  x --------------> [3]                   |
> |                     ^                    |
> |   y ----------------|                    |
> --------------------------------------------
>
> When I do x = [], a new object is created somewhere else on the page,
> and the name x is made to point to the new object. This changes the
> arrow. The name "x" is not in any way tied to the location of the [3]
> on the page. This doesn't impact "y" which is still pointing at the
> same spot it was before
>
> --------------------------------------------
> |  x -------->[]     [3]                   |
> |                     ^                    |
> |   y ----------------|                    |
> --------------------------------------------
>
> That is how Python's object model works. In CPython, objects have
> specified memory locations but names do not. In IronPython and Jython,
> even that's not guaranteed- the garbage collector can move the objects
> around during their lifetime, so while you can trust that a name will
> always point to the correct object, you have no guarantee about where
> the object is located in the computer's memory.
>
EXCELLENT EXPLANATION, THANK YOU VERY MUCH.
I AM SAVING THIS TO A .TXT FOR FUTURE REFERENCE.

THAT'S WHY I ASK YOU GUYS FOR HUMAN LIKE EXPLANATIONS.
THIS CANNOT BE FIND WITH SUCH SIMPLE WAY OF PUTTING THIS IN TECH DOCS.

Something else please:

The way some info(i.e. a Unicode string) is saved into the hdd , is the 
same way its being saved into the memory too? Same way exactly?

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).

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.

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

Thanks again Benjamin for making things clear.

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48567 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromTerry Reedy <tjreedy@udel.edu>
Date2013-06-17 18:16 -0400
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<mailman.3495.1371507400.3114.python-list@python.org>
In reply to#48540
On 6/17/2013 1:17 PM, Νίκος wrote:
>> On Mon, Jun 17, 2013 at 8:55 AM, Simpleton <support@superhost.gr> wrote:
>>> On 17/6/2013 5:22 μμ, Terry Reedy wrote:

>>>> When you interpret Python code, do you put data in locations with
>>>> integer addresses?

>>> I lost you here.

Memory in biological brains is not a linear series of bits, or 
characters. How we do associate things is still mostly a puzzle.

Read about holographic memory.

> The way some info(i.e. a Unicode string) is saved into the hdd , is the
> same way its being saved into the memory too? Same way exactly?

No. A unicode string is a sequence of abstract characters or codepoints. 
They must be encoded somehow to map them to linear byte memory. There 
are still (too) many encodings in use. Most cannot encode *all* unicode 
characters.

CPython is unusual in using one of three different encodings for 
internal unicode strings.

> While you said to me to forget about memory locations,

This is excellent advice. One of the *features* of Python is that one 
*can* forget about addresses. One of the *problems* of C is that many 
people *do* forget about memory locations, while virus writers study 
them carefully.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#48573 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-06-17 23:09 +0000
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<51bf9714$0$29872$c3e8da3$5496439d@news.astraweb.com>
In reply to#48514
On Mon, 17 Jun 2013 14:34:57 +0300, Simpleton wrote:

> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
>> Now, in languages like Python, Ruby, Java, and many others, there is no
>> table of memory addresses. Instead, there is a namespace, which is an
>> association between some name and some value:
>>
>> global namespace:
>>      x --> 23
>>      y --> "hello world"
> 
> First of all thanks for the excellent and detailed explanation Steven.
> 
> As for namespace:
> 
> a = 5
> 
> 1. a is associated to some memory location 

No. a is associated to an object, the int 5, which may be free to move in 
memory (PyPy does this), or may be at a fixed memory location (CPython 
does this). But the association is with the object, not the memory 
location.

The object is a data structure that contains a type (int), a value (5), 
and various methods (e.g. bit_length, to_bytes).


2. the latter holds value 5
> 
> So 'a', is a reference to that memory location, so its more like a name
> to that memory location, yes? Instead of accessing a memory address with
> a use of an integer like "14858485995" we use 'a' instead.

No. We're talking about what the Python interpreter does, not what you 
do. Whether you are programming in C or Python, you still refer to 
variables by name:

a = 5

but what goes on inside the interpreter or compiler is different.


> So is it safe to say that in Python a == &a ? (& stands for memory
> address)

Absolutely not.


> is the above correct?
> 
> I say this because here you said that: Instead, there is a namespace,
> which is anassociation between some name and some value:
> 
> When you say that you mean that a is associated to some value as in
> memory location or to that memory location's address?

No. This has nothing to do with memory locations. Namespaces are dicts. 
Write down a dict:

{"a": "Hello world"}

Do you see a memory location there? There is no memory location. There is 
the name, "a", and the object it is associated with, "Hello world". 
Either the dict, or the string, may move around memory if the underlying 
memory manager allows it. Obviously any object in Python must be 
*somewhere* in memory at any specific moment, but that is irrelevant to 
understanding Python code. It is no more relevant than saying that a dict 
{'a': 5} is just made up of bits.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#48577 — Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

FromΝίκος <support@superhost.gr>
Date2013-06-18 02:26 +0300
SubjectRe: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
Message-ID<kpo5vf$sa6$2@news.grnet.gr>
In reply to#48573
Στις 18/6/2013 2:09 πμ, ο/η Steven D'Aprano έγραψε:
> {"a": "Hello world"}
>
> Do you see a memory location there? There is no memory location. There is
> the name, "a", and the object it is associated with, "Hello world".
> Either the dict, or the string, may move around memory if the underlying
> memory manager allows it. Obviously any object in Python must be
> *somewhere* in memory at any specific moment, but that is irrelevant to
> understanding Python code. It is no more relevant than saying that a dict
> {'a': 5} is just made up of bits.

Okey, the easy part was to understand how humans in high level need to 
understand namespaces and assignment (which is not copying but instead 
referencing another name to the same object).

But i would like to know, what happens internally within the python 
compiler, because obviously memory is involved.

The way some info(i.e. a Unicode string) is saved into the hdd , is the 
same way its being saved into the memory too? Same way exactly?

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).

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.

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

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


Page 4 of 6 — ← Prev page 1 2 3 [4] 5 6  Next page →

Back to top | Article view | comp.lang.python


csiph-web