2

Is there any pythonic way to determine OS distribution/flavor?

cat /etc/issue shows me following -- [its CentOS 5.6]

[root@localhost Abhishek]# cat /etc/issue
CentOS release 5.6 (Final)
Kernel \r on an \m
Abhishek Kulkarni
  • 3,693
  • 8
  • 35
  • 42
  • 1
    open that file and read it? – LtWorf Jun 25 '13 at 13:58
  • Is your question intended to be restricted to just RHEL, CentOS and SUSE, or could it be Windows, BeOS, MacOS, *BSD, Plan 9 or VMS, too? – kojiro Jun 25 '13 at 13:59
  • It is specific to unix only.. and I want better Pythonic way.. However, thanks @soon I got the answer in the post you mentioned Its - platform.linux_distribution() – Abhishek Kulkarni Jun 25 '13 at 14:11

1 Answers1

2

Use sys.platform() to get the platform. Or for more detailed information use platform.platform()

>>> import platform
>>> print platform.linux_distribution()
('Ubuntu', '12.04', 'precise')

Note: platform.linux_distribution() has been deprecated since Python 3.5, and will be removed in Python 3.7.

chobok
  • 423
  • 4
  • 19
Paul Gladkov
  • 479
  • 5
  • 5