I have a case where a module may optionally exist. If it doesn't exist, it's OK.
I wrote this:
try:
import debug_trace
print "[FEATURE_TEST] ... loaded custom debug traces, from %s" % debug_trace.__file__
except ImportError:
# The file "debug_trace.py" probably doesn't exist
pass
then I realised that this is not achieving what I want, because it masks errors in the case where the file exists but it contains errors.
How can I safely import a module, if it exists... but, report errors if it contains them?