I think checking sys.modules should do instead, something like:
sentinel = object()
module = sys.modules.get(self.module_name)
if module is None:
return False
if module is sentinel:
try:
module = __import__(self.module_name, {}, {}, [''])
except ImportError: # import can raise other things, but that's a bug
return False
return True
That should save me worrying needlessly about exec on an interpolated string.
I think checking sys.modules should do instead, something like:
sentinel = object() get(self. module_ name) _(self. module_ name, {}, {}, [''])
module = sys.modules.
if module is None:
return False
if module is sentinel:
try:
module = __import_
except ImportError: # import can raise other things, but that's a bug
return False
return True
That should save me worrying needlessly about exec on an interpolated string.