[Tutor] import'ing problems (path) P.S.!!

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Oct 11 20:11:15 CEST 2004

On Tue, 5 Oct 2004, Tim Johnson wrote:

> * Kent Johnson <kent_johnson at skillsoft.com> [041005 10:51]:
> > It looks like WebKit doesn't want to see the Webware level in the package
> > hierarchy. You could take everything out of the Webware directory and put
> > it directly in site-packages or add the Webware directory to sys.path as I
> > described before. Then try import WebKit.Page (without the WebWare prefix).
>   Okay! add the following line:
>   sys.path.append('/usr/local/lib/python2.3/site-packages/Webware')
>   and the import is successful.

Hi Tim,

Ok, then this sounds like Webware has some silly problems with their
module imports.

Let me double check a few things... oh my goodness.  That doesn't look
right!  There are some places in the WebKit that do some wacky imports.
For example, Webware.WebKit.Object:

### Webware/WebKit/Object.py
import os, sys

        import MiscUtils
        # When the Webware tarball unravels,
        # the components sit next to each other
        import MiscUtils
from MiscUtils.NamedValueAccess import NamedValueAccess
[text cut]

They should not be dynamically fiddling with the system path like that!
They may need to rewrite that as:

import os.sys
from Webware import *
import MiscUtils

Since they designed the Webware package to be 'from [module] import *'
safe, they might as well use it.  *grin*

According to section 6.4.2 of the Python Tutorial (Intra-package


any module in the Webware.WebKit subpackage won't automatically see stuff
at the toplevel Webware package.  That's why they're running into import

But it looks like, rather than fixing the problem cleanly, they kludged a
solution that only works if the current working directory is at the
toplevel Webware directory.  Argh.

So the Webware developers to fix that; Webware needs to correct they way
they import packages.  The inner modules in ther should definitely NOT
make changes to the sys.path variable.

Hope this helps!

More information about the Tutor mailing list