Skip to main content

io.base

OutputStream

@runtime_checkable
class OutputStream(Protocol)

print

def print(*objects: Any,
sep: str = " ",
end: str = "\n",
flush: bool = False) -> None

将数据打印到输出流中。

参数

  • objects any - 要打印的数据。
  • sep str, 可选 - 对象之间的分隔符。默认为 " "。
  • end str, 可选 - 输出的结尾。默认为 " "。
  • flush bool, 可选 - 是否刷新输出。默认为 False。

InputStream

@runtime_checkable
class InputStream(Protocol)

input

def input(prompt: str = "", *, password: bool = False) -> str

从输入流中读取一行。

参数

  • prompt str, 可选 - 要显示的提示。默认为空字符串。
  • password bool, 可选 - 是否读取密码。默认为 False。

返回值

  • str - 从输入流中读取的行。

IOStream

@runtime_checkable
class IOStream(InputStream, OutputStream, Protocol)

用于输入/输出流的协议。

set_global_default

@staticmethod
def set_global_default(stream: "IOStream") -> None

设置默认的输入/输出流。

参数

  • stream IOStream - 要设置为默认的输入/输出流。

get_global_default

@staticmethod
def get_global_default() -> "IOStream"

获取默认的输入/输出流。

返回值

  • IOStream - 默认的输入/输出流。

get_default

@staticmethod
def get_default() -> "IOStream"

获取默认的输入/输出流。

返回值

  • IOStream - 默认的输入/输出流。

set_default

@staticmethod
@contextmanager
def set_default(stream: Optional["IOStream"]) -> Iterator[None]

设置默认的输入/输出流。

参数

  • stream IOStream - 要设置为默认的输入/输出流。