473,378 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
either.

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

------------------------------------------------------------------------

--
http://mail.python.org/mailman/listinfo/python-list
================================================== ========

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.

example:

#!/usr/local....
..
..
DvlpPATH=...... #usually a full hardcoded path ending with a '/'
#FnlPATH=.....
..
..
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.
Steve
norseman@hughesnet
Jul 18 '08 #1
0 1626

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Francisco Borges | last post by:
Hello, This is not stricly necessary but it would be nice if I could get it done. Here is what I want to do: There are 2 "foo" named modules, 'std foo' and 'my foo'. I want to be able to...
4
by: Bo Peng | last post by:
Dear list, What I would like to do is something like: In myModule.py ( a wrapper module for different versions of the module), if lib == 'standard': from myModule_std import * elsif lib ==...
12
by: qwweeeit | last post by:
The pythonic way of programming requires, as far as I know, to spread a big application in plenty of more manageable scripts, using import or from ... import to connect the various modules. In...
6
by: Kamilche | last post by:
I have a large project that is getting complex, and I would like to print the docstrings without importing the modules. The only Python utility I could find references is apparently defunct and...
19
by: Flavio | last post by:
hi, I have an object defined with a number of hardcoded methods. Class soandso: def __init__(self): self.this = 0 self.that = 1 def meth1(self): ...
0
by: Jure Vrscaj | last post by:
Hi, as title implies, I wrote a simple module that allows importing modules or even packages via http, conceptually similar to zipimport (of which I learned about during the process of writing...
14
by: T. Crane | last post by:
Hi, When troubleshooting code that's saved in a text file, I often find that I want to make a change to it, re-save it, then reimport it. However, just typing import myTestCode doesn't...
4
by: rshepard | last post by:
I'm stymied by what should be a simple Python task: accessing the value of a variable assigned in one module from within a second module. I wonder if someone here can help clarify my thinking. I've...
0
by: Fredrik Lundh | last post by:
mercado mercado wrote: if you already have two different versions of the script, what stops you from making changes to them? cannot you just insert the appropriate directory in sys.path...
3
by: rs387 | last post by:
Hi, I've found the following behaviour on importing a variable from a module somewhat odd. The behaviour is identical in Python 2.5 and 3.0b2. In summary, here's what happens. I have a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.