Python packages - problems, pitfalls.

Tim Roberts timr at probo.com
Tue Nov 6 01:24:40 EST 2001


Prabhu Ramachandran <prabhu at aero.iitm.ernet.in> wrote:
>
>Recently I discovered that there is some very unfortunate behaviour
>with python packages.
>
>Lets say I have a directory 'pkg' that is the root of a package.
>Inside this directory I have a sub-package, called sub.  So its
>something like:
>
>pkg/
>    __init__.py
>    a.py
>    sub/
>        __init__.py
>        b.py
>
>Now, from b I'd expect to be able to import 'a' straight away.
>
>Say in b.py I do
>
>import a
>
>This will not work!

But this will:

import os
os.path.append('..')
import a

That's what I've used in a similar situation.  Is that really so horrible?
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list