Importing from Another Path

Paul Sidorsky paulsid at home.com
Tue Jul 24 13:54:29 EDT 2001


I'm working on a client/server project (in Python 2.1) and I've got it
organized in the familiar structure of client, server, and common
subdirectories.  What is the correct (i.e. simplest and fastest) way to
import modules from the common directory into the client or server? 
Right now I'm doing it by putting this at the top of each module:

import sys
sys.path.append("..\\common")
del sys

This works, but a) I don't need sys so importing it seems like a waste,
b) it's obviously not portable (and using os.path.join() would add more
wastage), and c) it just seems ugly.  Is there a better way?  (I'm aware
of PYTHONPATH but it would be a pain to use in this case.)  I haven't
been able to locate any information on doing this.

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




More information about the Python-list mailing list