On Wed, Apr 15, 2009 at 6:57 PM, Alan Gauld <alan.ga...@btinternet.com> wrote:

> When you import you import names, in the first case webapp.
> Where the name is a package (ie a folder) that gives you access
> to the modules (or sub packages) contained in that folder but
> not to the contents of those items directly, hence the need for
> webapp.util.

In general, importing a package does not give access to members of a
sub-package. You have to explicitly import the subpackage. For
example,

In [1]: import xml

In [2]: xml.dom.Node
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/Users/kent/<ipython console> in <module>()

AttributeError: 'module' object has no attribute 'dom'

In [3]: import xml.dom

In [4]: xml.dom.Node
Out[4]: <class xml.dom.Node at 0x149eba0>

There are some exceptions, notably os.path:
In [5]: import os

In [6]: os.path
Out[6]: <module 'posixpath' from
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/posixpath.pyc'>

but that is a special case and requires special coding in the os module.

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to