speechbrain.utils.superpowers 模块

应该谨慎使用的超能力。

这个库包含用于导入Python文件和运行shell命令的函数。记住,能力越大,责任越大。

Authors
  • Mirco Ravanelli 2020

  • 阿库·罗赫 2021

摘要

函数:

import_from_path

从绝对路径导入模块

run_shell

此函数可用于在bash shell中运行命令。

参考

speechbrain.utils.superpowers.import_from_path(path)[source]

从绝对路径导入模块

Parameters:

path (str, pathlib.Path) – 要导入的模块的路径

Returns:

  • module – 已加载的模块

  • 实现取自

  • https (//docs.python.org/3/library/importlib.html#importing-a-source-file-directly)

speechbrain.utils.superpowers.run_shell(cmd)[source]

此函数可用于在bash shell中运行命令。

Parameters:

cmd (str) – 要运行的Shell命令。

Returns:

  • bytes – 捕获的标准输出。

  • bytes – 捕获的标准错误。

  • int – 返回码。

Raises:

OSError – 如果返回码不是0,即命令失败。

Example

>>> out, err, code = run_shell("echo 'hello world'")
>>> _ = out.decode(errors="ignore")