From: aa8vb at vislab.epa.gov (Randall Hopper)
Date: Fri, 23 Apr 1999 12:37:14 GMT
Subject: Pointers to variables
In-Reply-To: <021801be8d86$0d3ba7a0$f29b12c2@pythonware.com>; from Fredrik Lundh on Fri, Apr 23, 1999 at 02:37:27PM +0200
References: <19990422121403.A279051@vislab.epa.gov> <wkk8v4ef5e.fsf@turangalila.harmonixmusic.com> <19990423080721.A344578@vislab.epa.gov> <021801be8d86$0d3ba7a0$f29b12c2@pythonware.com>
Message-ID: <19990423083714.A321566@vislab.epa.gov>
Content-Length: 1074
X-UID: 330                                                  

Fredrik Lundh:
 |> but this one doesn't:
 |> 
 |>     (3)  min = 0
 |>          max = 0
 |>          for ( var, val ) in [( min,   1 ), ( max, 100 )]:
 |>            var = val
 |
 |here, you tell python to change the binding for the name "var"
 |in the local name space so it points to the same thing as the
 |name "val".

Ahh (light bulb goes on).  Makes sense.  I should have seen that (need my
morning caffeine).

When the "for" iterates, var is really an alias for min and max's storage
-- what you want.  But the problem is you can't "change" the value of
storage with assignment to var (that just rebinds var).

And Python being "pointerless" there is no:

     *var = val
or:
     memcpy( var, val, sizeof(*var) )

-like construct.  So you have to resort to other means (setattr).

 |> So basically this is just a little asymmetry in the language.  Putting a
 |> variable in a list/tuple (valueof(var)) performs a shallow copy rather than
 |> a deep copy.
 |
 |nope.  content is never copied.  only references.  all the time.
 |perfect symmetry.

Thanks.

Randall




