Importing different versions of a module

mercado mercado mercado949 at gmail.com
Thu Jul 17 19:14:56 EDT 2008


I have two versions of a script on my machine. One version is for new
development and the other version is a production version.  This script
imports a module from a different directory, and this module again has two
versions (a development version and a production version).  What I want is
for the development script to import the development module, and the
production script to import the production module, without making any
changes to the code in the script.

For example, suppose the development script is in ~/dev/rss.py, and the
production script is in ~/prod/rss.py.  I want the dev version to import
/usr/lib/python2.5/site-packages/lib_dev/parse.py, and the prod version to
import usr/lib/python2.5/site-packages/lib_prod/parse.py.

My first instinct was to place a .pth file in ~/dev that points to
/usr/lib/python2.5/site-packages/lib_dev, and a .pth file in ~/prod that
points to /usr/lib/python2.5/site-packages/lib_prod, but it seems that
site.py doesn't look at .pth files in the current working directory.  My
next attempt was to create a symbolic link in ~/dev called parse.py,
pointing to /usr/lib/python2.5/site-packages/lib_dev/parse.py, and a
symbolic link in ~/prod called parse.py, pointing to
/usr/lib/python2.5/site-packages/lib_prod/parse.py, but that didn't work
either.

Can anybody suggest a way to achieve my goal?  Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080717/f58f28f7/attachment.html>


More information about the Python-list mailing list