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

Print data to the output stream.

Arguments:

  • objects any - The data to print.
  • sep str, optional - The separator between objects. Defaults to " ".
  • end str, optional - The end of the output. Defaults to " ".
  • flush bool, optional - Whether to flush the output. Defaults to False.

InputStream

@runtime_checkable
class InputStream(Protocol)

input

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

Read a line from the input stream.

Arguments:

  • prompt str, optional - The prompt to display. Defaults to "".
  • password bool, optional - Whether to read a password. Defaults to False.

Returns:

  • str - The line read from the input stream.

IOStream

@runtime_checkable
class IOStream(InputStream, OutputStream, Protocol)

A protocol for input/output streams.

set_global_default

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

Set the default input/output stream.

Arguments:

  • stream IOStream - The input/output stream to set as the default.

get_global_default

@staticmethod
def get_global_default() -> "IOStream"

Get the default input/output stream.

Returns:

  • IOStream - The default input/output stream.

get_default

@staticmethod
def get_default() -> "IOStream"

Get the default input/output stream.

Returns:

  • IOStream - The default input/output stream.

set_default

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

Set the default input/output stream.

Arguments:

  • stream IOStream - The input/output stream to set as the default.