Modifying Class Object
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sat Feb 13 22:53:42 EST 2010
On Sat, 13 Feb 2010 18:54:34 -0800, Steve Howell wrote:
> On Feb 13, 6:41 pm, a... at pythoncraft.com (Aahz) wrote:
> > Regardless of how CPython manages its state internally, Python as a
> > programming language does not have pointers.
>
> I agree with your statement for a suitably narrow definition of the
> words "pointer" and "have."
"Suitably narrow" is not that narrow. By no stretch of the imagination
can one say that Python has a built-in pointer type analogous to pointers
in (say) Pascal or C -- you can't usefully get the address of a variable
(although the CPython implementation leaks the address of objects, it
does so in a way that is safe and useless for everything but a label).
There is no equivalent to (say) the Pascal program:
program main(input, output);
var
x: integer;
ptr: ^integer;
begin
x := 1;
ptr := @x;
ptr^ := ptr^ + 1;
writeln(x);
end.
For a suitably wide definition of "pointer", then Python does have
pointers:
data = ['aaa', 'bbb', 'ccc', 'ddd', 'eee']
i = data.index('bbb')
print data[i]
i += 1
data[i] = 'zzz'
but I trust that we all agree that describing the integer offset i above
as a "pointer" is a reductio ad absurdum.
--
Steven
More information about the Python-list
mailing list