1

Is there any way to check what platform I'm running with Python 2.7? For example using the platform module:

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

I get:

Linux
2.6.32-312-ec2

But if I read from the file /etc/issue by running a Linux command line command within Python I can get exactly what platform I'm 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 that I'm running Debian GNU Linux 6.0?

3
  • What does sys.platorm get you? Commented Mar 12, 2014 at 20:45
  • 2
    python -mplatform or platform.platform() in the code Commented Mar 12, 2014 at 20:48
  • related: When to use os.name, sys.platform, or platform.system? Commented Mar 12, 2014 at 20:50

3 Answers 3

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())
Sign up to request clarification or add additional context in comments.

Comments

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)

Comments

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
>>> 

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.