• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
PythonForBeginners.com

PythonForBeginners.com

Learn By Example

  • Home
  • Python Tutorial
  • Python Basics
  • Python Code Examples

 

You are here: Home / Basics / Using the Platform module in Python

Using the Platform module in Python

Last Updated: May 24, 2020

What is it used for?

The platform module in Python is used to access the underlying platform’s data,
such as, hardware, operating system, and interpreter version information.

The platform module includes tools to see the platform’s hardware, operating
system, and interpreter version information where the program is running.

How do I use it?

You start with importing the platform module in your program, like this:
import platform

You then specify what you want to find out (more on that below).

For example, if you want to find out which python version you are using,
simply add python_version() to the platform, like so:
print platform.python_version()

This will return the Python version as a string.

On my computer it looks like this:
2.7.3

Platform Functions

Let’s have a look at the different platform functions we can use

platform.architecture()
returns information about the bit architecture

platform.machine()
returns the machine type, e.g. ‘i386’.

platform.node()
returns the computer’s network name (may not be fully qualified!)

platform.platform()
returns a single string identifying the underlying platform with as much useful
information as possible.

platform.processor()
returns the (real) processor name, e.g. ‘amdk6’.

platform.python_build()
returns a tuple (buildno, builddate) stating the Python build number and
date as strings.

platform.python_compiler()
returns a string identifying the compiler used for compiling Python.

platform.python_version()
returns the Python version as string ‘major.minor.patchlevel’

Recommended Python Training

For Python training, our top recommendation is DataCamp.

Free Trial

platform.python_implementation()
returns a string identifying the Python implementation.
Possible return values are: ‘CPython’, ‘IronPython’, ‘Jython’, ‘PyPy’.

platform.release()
returns the system’s release, e.g. ‘2.2.0’ or ‘NT’

platform.system()
returns the system/OS name, e.g. ‘Linux’, ‘Windows’, or ‘Java’.

platform.version()
returns the system’s release version, e.g. ‘#3 on degas’

platform.uname()
returns a tuple of strings (system, node, release, version, machine, processor)
identifying the underlying platform.

Operating System and Hardware Info

Let’s show some examples with an output, to see how this works.

(you can find more examples here)

import platform

print 'uname:', platform.uname()

print
print 'system   :', platform.system()
print 'node     :', platform.node()
print 'release  :', platform.release()
print 'version  :', platform.version()
print 'machine  :', platform.machine()
print 'processor:', platform.processor()

Output

uname: (‘Linux’, ‘Mwork’, ‘3.5.0-21-generic’, ‘#32-Ubuntu SMP Tue Dec 11 18:51:59
UTC 2012’, ‘x86_64’, ‘x86_64’)

system : Linux
node : Mwork
release : 3.5.0-21-generic
version : #32-Ubuntu SMP Tue Dec 11 18:51:59 UTC 2012
machine : x86_64
processor: x86_64

Sources

Please see the following URL’s for more information

http://docs.python.org/2/library/platform.html
http://www.doughellmann.com/PyMOTW/platform/

Recommended Python Training

For Python training, our top recommendation is DataCamp.

Free Trial

Filed Under: Basics Date Originally Published: January 16, 2013

More Python Topics

API Basics Beautiful Soup bitly Cheatsheet Code Code Snippets Command Line crawler Data Types Development Dictionary Dictionary Data Structure In Python envoy Errorhandling Error Handling Exceptions Fabric Files fnmatch ftplib Games GUI Json Lists Loops Mechanzie Modules Modules In Python Mysql OS pil pip Python Python Code Snippets Python On The Web Python Strings Requests Scraping Scripts sh simplehttpserver System & OS urllib2 Web

Primary Sidebar

Get Our Free Guide To Learning Python

Menu

  • Python Basics
  • Code Examples
  • Loops
  • Functions
  • Strings
  • Python on the Web
  • Lists
  • Dictionaries
  • Python Modules
  • Python Glossary
  • Learn Python

Most Popular Content

  • Reading and Writing Files in Python
  • String Concatenation and Formatting
  • List Comprehensions in Python
  • How to use sys.argv in Python
  • How to use Split in Python
  • How to use comments in Python
  • Python Syntax Basics

Recent Posts

  • Datacamp Review 2020
  • Most Common Python Interview Questions For 2020
  • Python 2 Vs Python 3 with Examples
  • How To Run Your Python Scripts
  • The 5 Best Python IDE’s and Code Editors for 2019

Python Courses

  • Datacamp: Intro To Python
  • 2021 Complete Python Bootcamp
  • Python Mega Course: Build 10 Real World Apps
  • Python Data Science Bootcamp
  • Complete Python Developer: Zero to Mastery

Copyright © 2012–2021 · PythonForBeginners.com

  • Home
  • Contact Us
  • Privacy Policy
  • Write For Us