467,210 Members | 1,344 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,210 developers. It's quick & easy.

Re: Importing different versions of a module

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
  • viewed: 865
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Francisco Borges | last post: by
4 posts views Thread by Bo Peng | last post: by
12 posts views Thread by qwweeeit@yahoo.it | last post: by
6 posts views Thread by Kamilche | last post: by
19 posts views Thread by Flavio | last post: by
reply views Thread by Jure Vrscaj | last post: by
4 posts views Thread by rshepard@nospam.appl-ecosys.com | last post: by
reply views Thread by norseman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.