creating package question

infidel saint.infidel at gmail.com
Wed Nov 16 20:59:34 CET 2005


erick_bod... at comcast.net wrote:
> I think I have an answer to my own question.  In the
> WindowsComponents/__init__.py file, I have the following, that feels
> like a better answer for the problem.  Is there a better answer than
> this?
>
> import os, sys
> sys.path.append(os.path.join(os.getcwd(), 'Common'))

My solution to this is to use a .pth file.  In my site-packages folder
under the python installation, I have a file named infidel.pth.  This
file contains the path to the folder where I put all my python source
code (C:\src\py).  In your case, you could have the path to your 'root'
folder.

One of my projects is structured like this:

C:\src\py
    infidel\
        __init__.py
        models\
            __init__.py
            basemodel.py
        views\
            __init__.py
            baseview.py
        controllers\
            __init__.py

Now the controllers package can do imports like this:

from infidel.models import basemodel
from infidel.views import baseview

The point is that the .pth file in site-packages adds custom paths to
your sys.path




More information about the Python-list mailing list