Temporary Workaround When Multiple Python Versions Cause Problems

I wrote and maintain an AMR (automated meter reading) store/transfer system. The system is implemented in Python, and has both command line and Django components, which share Python modules. Django is using Python 2.6.6, and the command line version is using 2.7.3.

Last Spring, I had to use pysftp and wound up breaking the web application. There is no pysftp installed for Python 2.6.6.

Eventually, this server is going to be rebuilt, but, until it is, I restored the web site using a bit of a kludge, by performing this workaround. The web site (Django) component does not use pysftp.

It’s funny that until you try something, you don’t know if it will work. Here is the workaround:

import sys
import os

if our_python_version >= (2,7,3):
   import pysftp

Since Django was built using Python 2.6.6 and no Django modules use sftp this is a good workaround, until I can rebuild this server.

This is what I like about these more modern languages, like PythonClojure, and even languages like Perl. You can interdict during a module load.


Leave a comment

Filed under Automated Meter Reading, Django, python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s