newbie question about import

Scott David Daniels Scott.Daniels at Acm.Org
Thu Jun 3 18:04:10 CEST 2004

Craig wrote:
>... is it good style to do this to get the above behaviour:
> import sys
> sys.path.append(/my/include/path)
> import my-include-file
Assuming you quote properly, and your file is nicely named:
     import my-include-file

Typically you will only have one or two directories you need
to add, and you _can_ make a file "my.pth" which consists
of the directory names you care about, and throw "my.pth"
in <pythontop>/lib/site-packages

The idea is to keep the source as portable as possible.  Each OS
has a different syntax for directory names; you could easily
become non-portable that way.  Note the "append to sys.path"
solution does not address this.  Also note, code like:

     import sys
     if myextdir not in sys.path:

may work a little better for you.

-Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list