A class question
gagsl-py2 at yahoo.com.ar
Tue Oct 30 08:54:51 CET 2007
En Tue, 30 Oct 2007 02:51:39 -0300, Donn Ingle <donn.ingle at gmail.com>
>> While Java's variable declarations bear a superficial (syntactical)
>> similarity to C, their semantics is in fact equivalent to the
>> object-reference semantics we know in Python.
> I come from Z80A/GWBASIC/VB and a little C, I would describe a Python
> variable as a pointer - in that it contains the address of something.
> What that "something" is, is a little fuzzy. Right now I imagine it's to
> kind of structure which has meta info about the object as well as it's
> actual address.
> How far off would that be?
Almost true. A Python variable is a name inside a namespace, pointing to a
Python object. Many names may point to the same object, of course.
An object (in CPython) is a structure containing a reference count,
followed by a pointer to the object's type, followed by the object
contents itself. The object contents may as simple as a single value (e.g.
int or float objects) or rather complex (like the frame object which
contains about 18 other values, including many pointers to other
structures and arrays).
The object's type would be what you call the meta info, and contains the
type name, many pointers to functions (implementing the type methods) and
some flags describing the type behavior.
More information about the Python-list