本文整理汇总了Python中importlib.__import__方法的典型用法代码示例。如果您正苦于以下问题:Python importlib.__import__方法的具体用法?Python importlib.__import__怎么用?Python importlib.__import__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类importlib
的用法示例。
在下文中一共展示了importlib.__import__方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_module_availability
# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import __import__ [as 别名]
def check_module_availability(module_name, purpose):
import importlib
try:
importlib.__import__(module_name)
status = 'OK'
except ImportError:
status = 'FAIL'
print_status(module_name, purpose, status)
#
# Required.
#
示例2: load
# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import __import__ [as 别名]
def load(name):
try:
obj = __import__(name)
reload(obj)
return obj
except:
pass
try:
import importlib
obj = importlib.__import__(name)
importlib.reload(obj)
return obj
except:
pass
示例3: load
# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import __import__ [as 别名]
def load(name):
try:
obj = __import__(name)
reload(obj)
return obj
except:
pass
try:
import importlib
obj = importlib.__import__(name)
importlib.reload(obj)
return obj
except:
pass
示例4: test_VerboseMode
# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import __import__ [as 别名]
def test_VerboseMode(self):
self.assertFalse(metaknowledge.constants.isInteractive())
sys.stdout.isatty = lambda : True
self.assertTrue(metaknowledge.constants.isInteractive())
class ImportMock(unittest.mock.Mock):
def __call__(self, *args, **kwargs):
if args[0] == 'threading':
raise ImportError
else:
return importlib.__import__(*args, **kwargs)
with unittest.mock.patch('builtins.__import__', new_callable = ImportMock):#, NoThreadingImport):
#builtins.__import__ =
self.assertFalse(metaknowledge.constants.isInteractive()) #This will fail for setup.py test
#Failure for setup.py is what is supposed to happen as that would be an interactive enviroment