1

Is there any way to check what platform im running with python 2.7? For example using platform module:

import platform
print platform.system()
print platform.release()

I get:

Linux
2.6.32-312-ec2

But with the linux command I can get exactly what platform im running:

import command
print commands.getoutput('cat /etc/issue')

.

 Debian GNU/Linux 6.0 \n \l

Is there any other way in python to know im running Debian GNU Linux 6.0?

John Lapoya
  • 572
  • 1
  • 8
  • 20

3 Answers3

2

Probably platform.uname() or platform.platform()

at a guess at least (or potentially sys.platform may provide sufficient data)

For example:

import platform
print(platform.platform())

import sys
print(sys.platform)

import os
print(os.name)
anon582847382
  • 18,791
  • 5
  • 51
  • 56
Joran Beasley
  • 103,130
  • 11
  • 146
  • 174
2

I prefer sys.platform to get the platform. sys.platform will distinguish between linux, other unixes, and OS X while os.name is more general.

These are done by:

import sys
print(sys.platform)

import os
print(os.name)

For much more detailed information, use the platform module. This has cross-platform functions that will give you information on the machine architecture, OS and OS version, version of Python, etc. Also it has os-specific functions to get things like the particular linux distribution.

A small example, which actually seems the best way to do what you want:

import platform
print(platform.platform())
anon582847382
  • 18,791
  • 5
  • 51
  • 56
1

try in your python2 interpreter

>>> import platform
>>> print(platform.platform())
Linux-5.4.0-56-generic-x86_64-with-Ubuntu-20.04-focal
>>> 
>>> import sys
>>> print(sys.platform)
linux2
>>> 
>>> import os
>>> print(os.name)
posix
>>> 
perymerdeka
  • 523
  • 6
  • 12