Reputation: 592
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?
Upvotes: 1
Views: 475
Reputation: 823
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
>>>
Upvotes: 1
Reputation: 113930
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)
Upvotes: 2
Reputation: 20351
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())
Upvotes: 2