How to catch an ImportError non-recursively?

Viewed 216

Say we want to import a script named user.py, which may fail.

try:
   import user
except ImportError:
   logging.info('No user script loaded.')

How can we make sure to only catch the possible import failure of user.py itself, and not of the imports that may be contained in user.py?

2 Answers
Related