all Python 3Linux · macOSosfunction
os.uname
os — system
Return information about the operating system (kernel, host, release, machine). Availability: Unix.
Syntax
os.uname(...)
It does not exist on Windows; platform.uname or platform.system give portable system information. nodename is the machine's network name, also available as socket.gethostname. release is the kernel version, not the distribution's: for the Linux distribution name and version use platform.freedesktop_os_release.
Examples
import os
import platform
print(os.uname()) # → ? только Unix: posix.uname_result(sysname='Linux', nodename='myhost', release='6.8.0-45-generic', version='#45-Ubuntu SMP ...', machine='x86_64')
print(os.uname().sysname) # → ? только Unix: имя ядра, например Linux (на macOS — Darwin)
sysname, nodename, release, version, machine = os.uname() # → ? только Unix: результат распаковывается как кортеж из пяти строк
print(f'{sysname} {release} на {machine}') # → ? только Unix: например Linux 6.8.0-45-generic на x86_64
print(platform.uname().system) # → ? кроссплатформенная замена: Linux / Darwin / Windows (сам os.uname() на Windows бросает AttributeError)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy