472,371 Members | 1,607 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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

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 1493

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

Similar topics

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...
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 ==...
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...
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...
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): ...
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...
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...
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...
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...
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...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.