Python sequences by reference - how to make clear
ajs at ix.netcom.com
Thu Sep 19 20:27:25 CEST 2002
>Yes, this is fully in accordance with how the Python language should
> Res += [rec] inserts references to list object rec,
> which are further modified... (he should use copy(rec) instead).
Yes, this issue in various guises bit me for some time after I began using
Python (self.-taught, as a fist programming language).
It had always seemed to me that if there were a copy operator, or
(perferably, to me) that the functionality of the copy module were in the
language core as a built_in, that I would have been on clearer notice that
there was something fundamental in this
area to which I needed to pay attention and become attuned.
In looking into it I did find some discussion of the issue on python-list.
Interestingly it was also math/Numeric folk who seemed to be rasing the
question then and advocating something along the lines of a built_in
operator for copying. I however think that the issue is quite real for
anyone coming to Python without the benefit of either a programming
background or a formal structure within which they are being taught the
I have felt strongly that others have been too quick to advocate changes to
the language to address "special needs" cases. And that the special needs
cases of the novice have been over-emphasized in discussions, in general.
And I have confirmed to myself in the work I have been doing recently, which
is specifcally addressed to the non-programmer, that those "special needs"
can most often be quite adequately addressed by the right interface design,
using Python's out of the box capabilities..
I admittedly have little understanding of the full implications of a
suggestion to make the copy module capabilities built_in.
But I do believe, all things else being equal (which I suspect they are
not), it would be quite helpful.
More information about the Python-list