Problem with assigning variables of type List
wurmy at earthlink.net
Fri Aug 23 16:26:30 CEST 2002
Greg Ewing wrote:
> Hans Nowak wrote:
>> OK. That's two ways of looking at the same thing. I prefer to think of
>> things as objects with names bound to them, rather than pointers to
>> objects in boxes.
> But that only works when you *have* names. Many
> objects in a typical Python program don't have
> any names bound to them -- contents of lists,
> tuples, dicts, etc.
> You need some concept of boxes with pointers
> in them to make sense of all those. Once you
> have that, it seems natural to me to think
> of variables as named boxes.
I'm growing a bit tired of the debate, and since there's obviously several ways
to look at the same thing, it's kind of pointless to keep on argueing about
what is "right" way. (This includes people who send me private mail too. :-)
But here is one such way to look at it:
1. Everything is an object. How this is implemented in C (or Java, or Caml, or
whatever the underlying language is), is largely irrelevant, unles you hack the
C API (etc) of course.
2. Objects may have names bound to them. A name is simply a way to refer to the
object, but an object can be retrieved in other ways too.
3. Code like
x = "fubu"
y = x
is very different from equivalent-looking Pascal or C code, whatever anyone
might say. *Because* of this difference, I think the
objects-possibly-with-names-bound-to-them approach makes sense. Learn this, and
everything will (should) be clear. Use the conventional approach, and it will
be confusing, IMHO-- you'll have to resort to something like "they're still
boxes just like in language X, they just have pointers in them".
Python doesn't have pointers, and I'm damn glad it doesn't. Let's not introduce
them into an explanation of Python's internal model.
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/
More information about the Python-list