[Baypiggies] Suggestions?

Glen Jarvis glen at glenjarvis.com
Fri Oct 30 18:40:05 CET 2009

Because I've *always* learned something from this community this when
posting similar questions, I have the following snippet ..

This project is imported on all machines. The organization is one module
with reasonably small python files organized logically (backup.py,
diskspace.py, shared.py, webserver.py, etc.) These are menu driven
management scripts for someone doing operations.

In my backup.py file, I have the following imports (organized in groups per
PEP-8; http://www.python.org/dev/peps/pep-0008/). However, one of our hosts
intentionally doesn't have psycopg2 installed. How do most deal with the
conditional import, while still keeping the imports grouped at the top of
the file? Or, better yet, how do you deal with this? It's very tempting to
break convention and only import psycopg2 module in the functions that need
it. That seems extreme for just one node in our system, however.

The following feels messy to me... I've been living with it, but then, I
betcha someone at BayPIGgies has a good suggestion :)

from datetime import datetime, timedelta
import os
import subprocess
import sys
import tarfile
from optparse import OptionParser
# There is no psycopg2 on host '[snip]'
    from psycopg2 import connect
except ImportError:

from myproject import other_modules # you get the idea
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20091030/e77badc3/attachment.htm>

More information about the Baypiggies mailing list