How to detect the operating system with Python?

8

How can I do in Python to identify which operating system is being used?

    
asked by anonymous 23.11.2016 / 13:20

4 answers

8
import os
print(os.name)

This is usually what matters, what you can and can not use in your application.

If you really want to show someone what the operating system is or if you want to do something very specific to a specific version there you can use:

import platform
print(platform.system())
print(platform.release())

See running on ideone .

    
23.11.2016 / 13:24
7
 import os
 print os.name
 #Saída: posix
 import platform
 platform.system()
 #Saída: 'Linux'
 platform.release()
 #Saída: '2.6.22-15-generic'

Retired from this question

    
23.11.2016 / 13:23
2

Simple (like almost everything in Python: p) - The outputs are from the test I did in my SO

>>> import os
>>> print os.name
nt
>>> import platform
>>> platform.system()
'Windows'
>>> platform.release()
'10'
    
23.11.2016 / 13:23
2
import platform

#PEGAR A VERSÃO COMPLETA
print(platform.platform())
#PEGAR O SISTEMA OPERACIONAL
print(platform.system())
#PEGAR A VERSÃO DO SISTEMA OPERACIONAL
print(platform.release())
#PEGAR A VERSÃO COMPLETA DO SISTEMA OPERACIONAL
print(platform.version())
    
23.11.2016 / 13:26