unexpected behavior: did i create a pointer?

Peter Otten __peter__ at web.de
Tue Sep 11 13:34:57 EDT 2007


Am Sat, 08 Sep 2007 09:44:24 +0000 schrieb Steven D'Aprano:

> Ways that Python objects are not like C pointers:
> 
> (1) You don't have to manage memory yourself.
> 
> (2) You don't have typecasts. You can't change the type of the object you 
> point to.
> 
> (3) Python makes no promises about the memory location of objects.
> 
> (4) No pointer arithmetic.
> 
> (5) No pointers to pointers, and for old-school Mac programmers, no 
> handles.
> 
> (6) No dangling pointers. Ever.
> 
> (7) There's no null pointer. None is an object, just like everything else.
> 
> (8) You can't crash your computer by writing the wrong thing to the wrong 
> pointer. You're unlikely even to crash your Python session.
> 
> 
> 
> Ways that Python objects are like pointers:
> 
> (1) ... um... 
> 
> Oh yeah, if you bind the _same_ object to two different names, _and_ the 
> object is mutable (but not if it is immutable), mutating the object via 
> one name will have the same effect on the object -- the same object, 
> naturally -- bound to the other name.

Had you put it that way in the first place I would have stayed in in my
hole ;)

Peter



More information about the Python-list mailing list