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

PythonForBeginners.com

Learn By Example

  • Home
  • Learn Python
    • Python Tutorial
  • Categories
    • Basics
    • Lists
    • Dictionary
    • Code Snippets
    • Comments
    • Modules
    • API
    • Beautiful Soup
    • Cheatsheet
    • Games
    • Loops
  • Python Courses
    • Python 3 For Beginners
You are here: Home / Basics / Using the Platform module in Python

Using the Platform module in Python

Author: PFB Staff Writer
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’

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/

Related

Recommended Python Training

Course: Python 3 For Beginners

Over 15 hours of video content with guided instruction for beginners. Learn how to create real world applications and master the basics.

Enroll Now

Filed Under: Basics Author: PFB Staff Writer

More Python Topics

API Argv Basics Beautiful Soup Cheatsheet Code Code Snippets Command Line Comments Concatenation crawler Data Structures Data Types deque Development Dictionary Dictionary Data Structure In Python Error Handling Exceptions Filehandling Files Functions Games GUI Json Lists Loops Mechanzie Modules Modules In Python Mysql OS pip Pyspark Python Python On The Web Python Strings Queue Requests Scraping Scripts Split Strings System & OS urllib2

Primary Sidebar

Menu

  • Basics
  • Cheatsheet
  • Code Snippets
  • Development
  • Dictionary
  • Error Handling
  • Lists
  • Loops
  • Modules
  • Scripts
  • Strings
  • System & OS
  • Web

Get Our Free Guide To Learning Python

Most Popular Content

  • Reading and Writing Files in Python
  • Python Dictionary – How To Create Dictionaries In Python
  • How to use Split in Python
  • Python String Concatenation and Formatting
  • List Comprehension in Python
  • How to Use sys.argv in Python?
  • How to use comments in Python
  • Try and Except in Python

Recent Posts

  • Count Rows With Null Values in PySpark
  • PySpark OrderBy One or Multiple Columns
  • Select Rows with Null values in PySpark
  • PySpark Count Distinct Values in One or Multiple Columns
  • PySpark Filter Rows in a DataFrame by Condition

Copyright © 2012–2025 · PythonForBeginners.com

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