469,955 Members | 2,457 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,955 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.

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

Can anybody suggest a way to achieve my goal? Thanks in advance.


================================================== ========

Yes, but you may not like it.

I do what you do. Prod and devel subdirs.
I store the paths in a var at the top of my programs.
I change it(them) when the program graduates.


DvlpPATH=...... #usually a full hardcoded path ending with a '/'
PATH2USE=DvlpPATH #which gets changed to FnlPATH when graduating
# I keep the DvlpPATH until I'm positive I'm not
# going to send it back to school

x= os.open(PATH2USE+"pgm_or_file.ext", 'r+b')

and so forth
If the there is a need, I'll hardcode to a branch point and create sub
branch vars as needed and chain as needed.
company_one + accounting + payables + vendors
+ inventory + shelf + vendors
+ real_property + locations

company_two + (same as above)

you get the idea
YES! You do have to change the code. But in one place only once you are
correctly set.
Jul 18 '08 #1
0 1362

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 | 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
14 posts views Thread by T. Crane | last post: by
reply views Thread by Fredrik Lundh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.