Python Glossary Русский

Python 3.3+osterm

os.terminal_size

os — terminals and devices

The result type of os.get_terminal_size(): a named tuple (columns, lines).

Syntax

os.terminal_size((cols, lines))

It behaves like a named tuple: columns and lines are available by name and by index, so cols, rows = os.get_terminal_size() works. shutil.get_terminal_size returns it as well. The size is a snapshot: if the user resizes the window, query again (on Unix the SIGWINCH signal announces it).

Examples

import os
ts = os.terminal_size((80, 24))
print(ts.columns)   # → 80
print(ts.lines)   # → 24
print(ts)   # → os.terminal_size(columns=80, lines=24)
print(ts[0], ts[1])   # → 80 24 — это именованный кортеж, поля доступны и по индексу
cols, lines = ts
print(f'{cols}x{lines}')   # → 80x24

See also

Open in the full glossarydocs.python.orgReport an inaccuracy