[Python-Dev] ::

Paul Prescod paulp@ActiveState.com
Fri, 04 May 2001 17:03:05 -0700


I'll throw out a partially formed thought in case it is useful to
anybody.

"::" might be useful to solve another problem I've been struggling with:
how to have multiple package distributions share a namespace
(xml::dom::minidom, xml::dom::4dom, xml::dom::corbadom). 

"::" might mean, in general, that you are walking through abstract,
potentially merged namespaces and not through concrete dictionary
implementations. I think that Python's using the same syntax for package
namespaces and attribute accesses might seem more elegant than it is in
practice. Things that "seem like" they should work do not because
packages are fundamentally different than attributes:

>>> from xml import dom.minidom
  File "<stdin>", line 1
    from xml import dom.minidom
                       ^
SyntaxError: invalid syntax

Why isn't this symmetric? I would like to use "." on either side of the
import

>>> import xml
>>> print xml.dom
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'xml' module has no attribute 'dom'
>>> from xml.dom import minidom
>>> print xml.dom
<module 'xml.dom' from 'c:\program
files\python21\lib\xml\dom\__init__.pyc'>

I find it a little bit weird that importing one module has the side
effect of populating a package.
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook