Package question.

Scott David Daniels Scott.Daniels at Acm.Org
Mon Sep 29 19:43:02 EDT 2003


Ian Sparks wrote:
> ... On Windows, I want to set up a package structure like :
> Fred\
>   Bob\
>     test.py
> So I can say :
>     from Fred.Bob import *
> To do this I need to put the package on the python path. 
 > So I drop this into my python root in a file called Fred.pth :
>     C:\Fred\
> Now to make sure that Fred and Bob both look like packages with 
 > empty __init__.py files like so :
>     C:\Fred\
>        __init__.py
>     C:\Fred\Bob\
>        __init__.py
>        test.py

> so :
> C:\python.exe -c from Fred.Bob import *
> OK!
But this is a lucky accident.  If you do:
     import sys
     for number, name in enumerate(sys.path):
         print number, repr(path)
You'll see (I suspect) that '' is on your path, and the Fred.pth
value is irrelevant (it adds an entry for 'C:\\Fred\\', which allows
you to import from Bob, not Fred.  You Fred.pth file should list the
directory _containing_ Fred (in this case, 'C:\\', not 'C:\\Fred\\').

Note, you'll still be surprised soon, because I suspect you think
that after:
     from Fred.Bob import *
you can freely use:
     test.somefunction()

-Scott David Daniels
Scott.Daniels at Acm.Org





More information about the Python-list mailing list