module confusion

Carsten Haese carsten at uniqsys.com
Thu Oct 4 02:12:53 CEST 2007


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.

>  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.

>  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?

> Honestly, why do people react to the word "pointer" as though computers have
> to wear underwear to conceal something shameful going on in their nether
> regions?

I won't speak for "people", but maybe it's because Python acts precisely
as this underwear that does conceal the low-level regions of memory
management and bit-twiddling that Python programmers like to avoid in
favor of solving higher-level problems.

If it helps you to think of Python names as "kind of like pointers,"
you're free to do so, but it's only a weak analogy that can lead
beginners to drawing incorrect conclusions.

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list