473,320 Members | 1,858 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,320 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.
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
0 1078

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...
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: norseman | last post by:
mercado mercado wrote: =================================== I started to import a module using its path and now see what you mean. Python is missing the concept: Programmer dictates what machine...
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.