I have a module that uses lxml. Since this cannot be imported on GAE, I'd like to use a suitable substitute by default. Something along the lines of:
if not ON_GAE:
How can I determine that I'm on GAE? Is there a OS variable of some sorts?
Update: There are certain modules that will not run on GAE (like
sockets). Rather than having multiple blocks of
except ImportError, I'd like to know from the start which code blocks needs an alternative implementation.
You can use this:
on_app_engine = os.environ.get('SERVER_SOFTWARE', '').startswith('Google')
Then something like:
if on_app_engine: import lxml else: import bla
You can simply try and see if an import throws an exception and use the other import only if it's necessary.
try: import lxml except ImportError: import beautifulsoup