Python os: Difference between revisions

From wikinotes
(Created page with "Python primarily stores information about the operating system in the <code>sys</code> and <code>platform</code> modules. = Operating System = <blockquote> <syntaxhighlight l...")
 
No edit summary
 
Line 1: Line 1:
Python primarily stores information about the operating system in the <code>sys</code> and <code>platform</code> modules.
Python primarily stores information about the operating system in the <code>sys</code> and <code>platform</code> modules.
= Python Info =
<blockquote>
<syntaxhighlight lang="python">
import sys
import platform
sys.executable      # the running python interpreter
sys.version_info()  # running python version
platform.libc_ver()  # libc that python was built with
</syntaxhighlight>
</blockquote><!-- Python Info -->


= Operating System =
= Operating System =
Line 12: Line 24:


platform.system()  # Linux, Windows, ...
platform.system()  # Linux, Windows, ...
platform.libc_ver()
platform.version()
platform.uname()    # kernel info
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Operating System -->
</blockquote><!-- Operating System -->
Line 22: Line 35:


platform.node()    # hostname
platform.node()    # hostname
platform.version()
platform.uname()    # kernel info
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Machine -->
</blockquote><!-- Machine -->

Latest revision as of 20:41, 31 July 2021

Python primarily stores information about the operating system in the sys and platform modules.

Python Info

import sys
import platform

sys.executable       # the running python interpreter
sys.version_info()   # running python version
platform.libc_ver()  # libc that python was built with

Operating System

import sys
import platform

sys.platform  # linux, linux2, FreeBSD, win32, darwin, ...
if sys.platform.startswith('linux'):
    # ...

platform.system()  # Linux, Windows, ...
platform.version()
platform.uname()    # kernel info

Machine

import platform

platform.node()     # hostname