用法:
test.support.import_helper.import_fresh_module(name, fresh=(), blocked=(), deprecated=False)
此函數通過在導入之前從
sys.modules
中刪除命名模塊來導入並返回命名 Python 模塊的新副本。請注意,與reload()
不同,原始模塊不受此操作的影響。fresh
是一個可迭代的附加模塊名稱,這些名稱在導入之前也會從sys.modules
緩存中刪除。blocked
是一個可迭代的模塊名稱,在導入期間在模塊緩存中替換為None
以確保嘗試導入它們會引發ImportError
。在開始導入之前保存命名模塊以及在
fresh
和blocked
參數中命名的任何模塊,然後在全新導入完成後重新插入sys.modules
。如果
deprecated
是True
,則在此導入期間會抑製模塊和包棄用消息。如果無法導入命名模塊,此函數將引發
ImportError
。示例使用:
# Get copies of the warnings module for testing without affecting the # version being used by the rest of the test suite. One copy uses the # C implementation, the other is forced to use the pure Python fallback # implementation py_warnings = import_fresh_module('warnings', blocked=['_warnings']) c_warnings = import_fresh_module('warnings', fresh=['_warnings'])
3.1 版中的新函數。
相關用法
- Python test.support.catch_unraisable_exception用法及代碼示例
- Python test.support.load_package_tests用法及代碼示例
- Python test.support.check_impl_detail用法及代碼示例
- Python test.support.captured_stdin用法及代碼示例
- Python test.support.check__all__用法及代碼示例
- Python test.support.threading_helper.catch_threading_exception用法及代碼示例
- Python test.support.warnings_helper.check_warnings用法及代碼示例
- Python numpy testing.decorators.slow用法及代碼示例
- Python numpy testing.decorators.setastest用法及代碼示例
- Python tesnsorflow.grad_pass_through()用法及代碼示例
- Python textwrap.indent用法及代碼示例
- Python tensorflow.eye()用法及代碼示例
- Python tensorflow.fill()用法及代碼示例
- Python tensorflow.math.special.dawsn()用法及代碼示例
- Python tensorflow.ensure_shape()用法及代碼示例
- Python tensorflow.math.special.fresnel_cos()用法及代碼示例
- Python tensorflow.raw_ops.Cos()用法及代碼示例
- Python tensorflow.get_logger()用法及代碼示例
- Python tensorflow.math.sqrt()用法及代碼示例
- Python tensorflow.math.atanh()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 test.support.import_helper.import_fresh_module。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。