w3resource
Python Exercises

Python: Display some information about the OS where the script is running

Python Basic - 1: Exercise-10 with Solution

Write a Python program to display some information about the OS where the script is running.

Sample Solution:

Python Code:

import platform as pl

os_profile = [
        'architecture',
        'linux_distribution',
        'mac_ver',
        'machine',
        'node',
        'platform',
        'processor',
        'python_build',
        'python_compiler',
        'python_version',
        'release',
        'system',
        'uname',
        'version',
    ]
for key in os_profile:
  if hasattr(pl, key):
    print(key +  ": " + str(getattr(pl, key)()))

Sample Output:

architecture: ('64bit', 'ELF')
linux_distribution: ('Ubuntu', '16.04', 'xenial')
mac_ver: ('', ('', '', ''), '')
machine: x86_64
node: 9a911676793b
platform: Linux-4.4.0-57-generic-x86_64-with-Ubuntu-16.04-xenial
processor: x86_64
python_build: ('default', 'Nov 17 2016 17:05:23')
python_compiler: GCC 5.4.0 20160609
python_version: 3.5.2
release: 4.4.0-57-generic
system: Linux
uname: uname_result(system='Linux', node='9a911676793b', release='4.4.0-57-generic', version='#78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016', machine='x86_64', processor='x86_64')
version: #78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016

Flowchart:

Flowchart: Python - Display some information about the OS where the script is running

Python Code Editor :

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to get a list of locally installed Python modules.
Next: Write a Python program to check the sum of three elements (each from an array) from three arrays is equal to a target value. Print all those three-element combinations.

What is the difficulty level of this exercise?