Exception Attributes
ImportError.name — exception attribute
Inspect the module name associated with an import failure. It can be set by the importer or a custom exception constructor; it may be None. ModuleNotFoundError inherits it. Do not assume a missing module name always equals the top-level import request.
Formal Syntax & Structure
python syntaxpython
error.nameReturn Value
str | None
Module name when available.
Working Example
Example Snippetpython
try: import bytemind_missing_demo_28except ModuleNotFoundError as error: print(error.name)