[Tutor] Import Modules

ALAN GAULD alan.gauld at btinternet.com
Thu Apr 16 09:21:37 CEST 2009

> 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)
> AttributeError: 'module' object has no attribute 'dom'

> There are some exceptions, notably os.path:
> In [5]: import os
> In [6]: os.path
> but that is a special case and requires special coding in the os module.

Interestingly I added the comment about sub packages specifically 
because I remembered os.path and assumed it was the norm! :-)

I really must read up on packages. I will need to for my v3 rewrite 

Alan G.

More information about the Tutor mailing list