Importing from Another Path

Paul Sidorsky paulsid at home.com
Tue Jul 24 17:24:47 EDT 2001


Ype Kingma wrote:

> > sys.path.append("..\\common")
> That is almost as portable as it gets: when also you take
> the common directory from the command line sys.argv, eg:
> 
>   sys.path.append(sys.argv[1])
> 
> I wouldn't know of a more portable way.
> The non portable part is then moved into the script(s) that
> start(s) the client and the server.

Actually I just meant that it wasn't portable between Windows and Linux
because I'm using backslashes in the path.

It looks like I'll have to just clean it up to use os.path.join() to
take care of that and live with it the way I've got it.  This is not the
answer I was hoping to hear, but at least it's an answer.  Thanks!

> Also you should be aware that the sys module (any imported module
> in fact) is unique in the process that runs the python interpreter,
> so you should not add the common directory when it is already there:
> 
>   if sys.argv[1] not in sys.path: sys.path.append(sys.argv[1])

Ah, good point.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid at home.com                      http://members.home.net/paulsid/




More information about the Python-list mailing list