Search code examples
pythonmoduleiooperating-system

Is it possible to detect the OS core is DOS or NT in Python?


The following code:

import os
print(os.name)

However, when I use Windows Me(DOS core) or Windows NT 4.0 Workstation SP6(NT core), the output is the same: nt .
So is it possible to detect the OS core is DOS or NT in Python? If it is, how?


Solution

  • You can use 'platform' module to check:

    In [244]: import platform
    
    In [247]: platform.version()
    Out[247]: '6.1.7601'
    
    In [248]: platform.system()
    Out[248]: 'Windows'
    
    In [249]: platform.release()
    Out[249]: '7'
    
    In [250]: platform.win32_ver()
    Out[250]: ('7', '6.1.7601', 'SP1', 'Multiprocessor Free')
    
    In [268]: platform.platform()
    Out[268]: 'Windows-7-6.1.7601-SP1'