module confusion

Neil Cerutti horpner at yahoo.com
Thu Oct 4 15:53:14 CEST 2007


On 2007-10-03, Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:
> In message <874ph8sdhx.fsf at benfinney.id.au>, Ben Finney wrote:
>
>> Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> writes:
>> 
>>> On my Gentoo system:
>>> 
>>>     >>> import os
>>>     >>> os.path
>>>     <module 'posixpath' from '/usr/lib64/python2.5/posixpath.pyc'>
>>> 
>>> It's just a variable that happens to point to the posixpath module.
>> 
>> There's no "pointing" going on. It's another name bound to the
>> same object, of equal status to the 'posixpath' name.
>> 
>> Python doesn't have pointers, and even "variable" is a
>> misleading term in Python. Best to stick to "name" and "bound
>> to".
>
> In Python, all names _are_ variables. They are not "bound" to
> objects. The value of os.path is a pointer. It's implemented as
> a pointer, it has all the semantics of a pointer.

No. A pointer is also an iterator.

void duplicate(char *d, const char *s)
{
  while (*d++ = *s++)
    ;
}

What does that look like implemented with Python names?

def duplicate(d, s):
  raise AbstractionViolationError("Python identifiers aren't pointers.")

Moreover, it seems difficult to promote the concept of a pointers
in a language which doesn't provide a "take the address of an
object" operation.

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

Refraining from thinking about pointers (unless I have to) saves
wear and tear on the old bean.  I also like to think of 5 as an
integer most of the time.

-- 
Neil Cerutti
Will the last person to leave please see that the perpetual light is
extinguished --sign at New England church



More information about the Python-list mailing list