list.remove for Novices

Jeff Shannon jeff at ccvcorp.com
Tue Nov 27 17:50:37 EST 2001


Arthur Siegel wrote:

> How about this one.  A copy operator -  <=> or something.  So now
> all the world is on notice from day one = is different that <=>.
> Which do you mean?

Well, Python already *does* have several ways to indicate copying, though not
specifically in a single simple operator like that.

list2 = list1[:]   #create a copy

import copy
list2 = copy.copy(list1)  #copies a list
list2 = copy.deepcopy(list1)  #even better

Yes, beginners are likely to get bitten by a few things.  This will happen
regardless of what language they use.  Trust me, it's a lot easier to track down
an assignment/copy error, or the list.reverse() gotcha, than to track down the
bugs caused by referencing free()'d memory in C...

I don't think that changing the language to avoid these will help matters much.
What *might* help, is changing the documentation.  If you think that having
these things clearly explained in the tutorial would help, by all means, submit
a patch for the tutorial!  That's probably much more effective (and more likely
to be accepted) than altering the language would be...

(Note that I consider myself almost a beginner--my programming knowledge is
entirely self-taught, starting with C, then C++, and now Python.  I've been
bitten by both of the traps that you mention.  But... any language will have
pitfalls to watch out for, provided that it's powerful enough to be useful.
With no reference but Python, it may not be obvious, but really--these are
*simple* traps to catch and avoid, compared to those of certain other
languages...)

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list