import subprocess def get_os_(): output = subprocess.getoutput("systeminfo") os_name_string_no_spaces=output.split("\n")[2].replace(" ","") print(os_name_string_no_spaces.split(":")[1].strip()) get_os_()