It’s not really nice, but you can get the exception message and extract the module name:
try:
import xyz
except ImportError as e:
print(e.message)
This prints ‘No module named xyz’.
Don’t now if it works for dotted/package imports.
···
On Saturday, July 11, 2015 at 7:31:08 AM UTC+7, Boštjan Mejak wrote:
I know that my question is going to be more Python than wxPython related, but I’m desperate.
Look at this code:
try:
import xyz
except ImportError:
print(“{moduleName} does not exist.”.format(moduleName=???))
Is there any way I can get the name of the module that threw the exception, so that the string would say “xyz does not exist.”? And if the module is in a package, the module name should include its package name + module name, like abc.xyz.
Got any idea? I have been googling for days now and I can’t find a satisfactory result. The info on the topic is confusing. Please help.