This is a bit hacky, but you can check the exception message to determine if it failed:
try: from mylibrary.codecs import optional except ImportError, e: if e.message != 'No module named optional': raise
With this code, when importing an additional module fails, it is ignored, but if something else throws an exception (import of another module, syntax errors, etc.), it will be raised.
glyphobet
source share