
Using os module
In Python 3.6/3.7, you can use os
module
os.name
: The name of the operating system dependent module imported. The following names have currently been registered: ‘posix’, ‘nt’, ‘java’.
so if os.name
is 'nt'
means windows os:
import os
if os.name == 'nt':
...
Code language: JavaScript (javascript)
Using platform.system
system()
Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'.
An empty string is returned if the value cannot be determined.
Code language: PHP (php)
On a 64 bit machine, with Windows 7 (64 bit OS) this is the output:
>>> print(sys.platform)
win32
>>> platform.win32_ver()
('post2008Server', '6.1.7100', '', 'Multiprocessor Free')
Code language: PHP (php)
Using sys module
import sys
# its win32, maybe there is win64 too?
is_windows = sys.platform.startswith('win')
Code language: PHP (php)