python - Figuring out what REALLY went wrong when an `ImportError` is raised -


take django instance, in manage.py:

try:     import settings except importerror:     sys.stderr.write("error: can't find file 'settings.py'...") 

seems legit, happens when settings imports non_existant_lib_foo?

well, you're sent on goose chase possible things have done path, etc.

of course can use except importerror e: , print out actual error message, if want catch specific error , give bit of advice, above?

you're left using regexp more or less or, @ best, guessing "right" module failed importing, , display message.

is there better way handle this?

basically problem error message wrong - there other reasons why import can fail, not wrong paths. importerror means "you cannot use module, @ traceback find out why", jumped conclusion.

if want display "can't find file" should file first. imp.find_module that.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -