Package question.

Ian Sparks Ian.Sparks at etrials.com
Tue Sep 30 08:54:46 EDT 2003


This makes sense, thanks.

-----Original Message-----
From: Scott David Daniels [mailto:Scott.Daniels at Acm.Org]
Sent: Monday, September 29, 2003 7:43 PM
To: python-list at python.org
Subject: Re: Package question.


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

-- 
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list