Python annoyance
Given the following code:
def index():
try:
import MySQLdb
except:
return "Couldn't import MySQL module"
return "Yay Workyness"
inside a mod_python instance, is there any reason why it should return “Yay Workyness” and “Couldn’t import MySQL module” in roughly equal amounts? (MySQLdb in this case is a sub directory of the current working directory). Bugs I can cope with, but this inconsistancy is driving me insane…
Simon Willison:
I good rule of thumb is that naked excepts are eeeevil and should be avoided at all costs. The problem is that you don’t know if you’re catching an ImportError or an error deeper down, somewhere in the MySQLdb module itself. Change your except line to “except ImportError” and see if you get a different exception rising to the top.
Aquarion:
That makes sense. Still don’t know what’s going on, but asking my Friendly Neighbourhood Sysadmin to install the module globally appears to have made it Go Away
Rory Parle:
I like your header graphic. It seems Mr Adams is spending rather more than a year dead for tax reasons. Unfortunately the world is doing a woeful job of finding a replacement.