By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,628 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,628 IT Pros & Developers. It's quick & easy.

Re: Importing different versions of a module

P: n/a
mercado mercado wrote:
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.
if you already have two different versions of the script, what stops you
from making changes to them?
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.
cannot you just insert the appropriate directory in sys.path the first
thing you do in the scripts? e.g.

import os, sys

lib = "lib_dev" # change this for prod/rss.py

sys.path.insert(0,
os.path.join(
os.path.dirname(os.__file__), "site-packages", lib
))

import parse # picks the right one

</F>

Jul 21 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.