redirect_fd

(类来自 pyomo.common.tee)

class pyomo.common.tee.redirect_fd(fd=1, output=None, synchronize=True)[source]

基础类:object

将文件描述符重定向到新文件或文件描述符。

此上下文管理器将重定向指定的文件描述符到指定的新输出目标(文件名或文件描述符)。对于文件描述符1(stdout)和2(stderr)的特殊情况,我们还将确保Python的sys.stdoutsys.stderr仍然可用:在synchronize=True的情况下,sys.stdout / sys.stderr文件句柄指向新的文件描述符。当synchronize=False时,我们保留Python文件对象的行为(如果需要,将其重定向到原始文件描述符)。

Parameters:
  • fd (int) – 要重定向的文件描述符

  • 输出 (intstr) – fd 的新输出目标:可以是另一个有效的文件描述符(int)或要打开的文件的字符串。

  • synchronize (bool) – 如果为True,并且fd为1或2,则更新sys.stdoutsys.stderr以指向新的文件描述符

__init__(fd=1, output=None, synchronize=True)[源代码]

方法

__init__([fd, output, synchronize])

成员文档