-1

I am trying to create a python script that runs on Linux, but in my script I want to check on which linux distribution it's running.

I found this code:

import platform
print(platform.linux_distribution())

but this returns: ('Ubuntu', '18.04', 'bionic') And all I need to check is if it's Ubuntu / centOS... (doesn't matter which version) How can I grep the first value and do a 'if' on it?

2
  • have you tried platform.linux_distribution()[0] already? Commented Nov 29, 2020 at 8:59
  • Does this answer your question? How to get the system info with Python? Commented Nov 29, 2020 at 9:58

1 Answer 1

0

The return value is a tuple , you can use the index to fetch the desired value

from platform import linux_distribution

dist_tup = linux_distribution()

if dist_tup[0] == "Ubuntu":
   ##### Do Something
else:
   ##### Do something else
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.