Modifying Class Object

John Posner jjposner at
Mon Feb 15 20:24:23 CET 2010

Alf said (2/13/2010 8:34 PM):

> Names in Python refer to objects.
> Those references can be copied via assignment.
> That's (almost) all.
> And it provides a very short and neat way to describe pass by sharing.

Alf also said (2/13/2010 8:43 PM):

> * Steve Howell:
> > This thread is interesting on many levels.  What is the core
> > question that is being examined here?
> I think that regarding the technical it is whether a Python name
> refers to an object or not. I maintain that it does, and that the
> reference can be copied, and that the semantics of the language
> requires this and is defined in terms of this. Steve Holden,
> D'Aprano and many others maintain that there are no references, or
> that if there are then they're only an implementation aspect, i.e.
> that conceiveable one could have an implementation without them.

Steve D'Aprano said (2/14/2010 12:13 AM):

> That's not to say that the general concept of references (as in "to
> refer to") isn't valuable when discussing Python. If you want to say
> that (e.g.) following
> x = 1
> the name "x" refers to (or even points to!) the object 1, my
> objections will be mild or non-existent. In that sense, it's probably
> impossible to program without some sort of "references": the computer
> manipulates variables or objects directly, while we manipulate
> characters in source code. The only way to write a program is to use
> some abstract thing (a name, an offset, whatever) that refers, in
> some fashion, to a collection of bits in the computer's memory. But
> to go from that to the idea that (say) x is a pointer does so much
> violence to the concept of pointer and has so much room for confusion
> that it is actively harmful.

I think most of the technical argument in this thread comes down to the
various forms of the word *refer*. After execution of this Python statement:

   x = 5

... we can use this English-language statement:

   the name *x* refers to the value *5*

(If anyone has more than Steve's "mild" objection, please speak up!)

The English-language statement uses the VERB "refers". It is not the 
same as using the NOUN "reference":

   *x* is a reference to the value *5*

Why not? Because using the NOUN form suggests that you're talking about
a particular kind of object in the world Python, as in these statements:

   *x* is a string
   *x* is a function
   *x* is a class

But Python does not define *reference* objects -- by which I mean that
executing *import types; dir(types)* produces a long list of object-type 
names, and there's nothing like a "reference" on that list.

(I suspect there's a better way to make this "there are no reference
objects" argument. Can anyone help?)

Amending the statement to:

   the name *x* is a reference to the value *5*

... doesn't really help matters. Is *x* a NAME or is it a REFERENCE?

Looking again at Alf's assertion:

> [the core technical question is] whether a Python name
> refers to an object or not. I maintain that it does, and that the
> reference can be copied,

... and Alf's example (message dated 2/10/2010 5:02 PM):

> For example,
>   x = s[0]
> accesses the object that s points (refers) to.

I believe Alf would characterize this assignment statement as a 
situation in which "a reference is copied" [using the NOUN form of 
"refer"]. But no object is copied during execution of this statement. 
Moreover, saying "a reference is copied" might mislead a Python newbie 
into thinking that some kind of "reference object" exists that can be 
copied by Python statements. So it's better to describe the situation 
using the VERB form of "refer":

   assigns the name *x* to the object that *s[0]* refers to


More information about the Python-list mailing list