module confusion

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Oct 4 06:38:42 EDT 2007


Lawrence D'Oliveiro a écrit :
> In message <mailman.1487.1191456788.2658.python-list at python.org>, Carsten
> Haese wrote:
> 
>> On Thu, 2007-10-04 at 11:11 +1300, Lawrence D'Oliveiro wrote:
>>
>>> In Python, all names _are_ variables. They are not "bound" to objects.
>>> The value of os.path is a pointer.
>> No. "os.path" refers to the object that's known as the "path" attribute
>> of the object known as "os". That object, in turn, is a module.
> 
> No, it's a variable. It just happens to contain a pointer to a module.

Lawrence, you should have a look at CPython's source code. And at other 
implementations too. Python's "variables" *really* are name/object pairs 
- most of the time key/value pairs in a dict. The name itself is just 
that : a name. It doesn't "contains" anything, it's *not* a label for a 
memory address, it's *only* a name.

>>>  It's implemented as a pointer,
>> While it is true that namespaces are implemented in CPython as
>> collections of pointers to PyObject structures, that's an irrelevant
>> implementation detail. I doubt that they are implemented as pointers in
>> Jython, PyPy, or IronPython.
> 
> I'll bet they are.

Since Java doesn't have pointers, you lost your bet.

>>>  it has all the semantics of a pointer.
>> No, it doesn't. A pointer means the physical address of a memory
>> location, which implies that you can overwrite that memory location. Can
>> you do that in Python?
> 
> Yes. Look up the definition of "mutable objects".

I think Carsten knows this definition. But it has nothing to do with 
"overwriting a memory location" - like you could do in C using pointers.




More information about the Python-list mailing list