/* jquery */ /* jquery accordion style*/ /* jquery init */

Raspberry Pi Python: Module Exploration

One of the reasons Python is so popular is it's large collection of modules.

They support a wide range of programming activities including mathematics, graphical user interfaces (GUI), file operations, image manipulation, turtle graphics and games.

The question is how do you discover the functionality provided by a particular module?

Here's a step-by-step process to explore any Python module.

Step 1: Start an Interactive Mode Session

Boot up your Raspberry Pi and begin a Interactive Mode session in a new terminal window.

Step 2: Import a Module

To work with a module you'll need to import it first. Type åin the following statement next to the '>>>' prompt and press the 'Enter' key:

>>> import platform

Step 3: Use dir()

Now type in the following statement next to the '>>>' prompt and press the 'Enter' key:

>>> dir(platform)

What you'll see is a list of the names (which includes variables and functions) defined by the 'platform' module. Each name is enclosed in single quotes.

Step 4: Use help()

Next try this statement:

>>> help(platform)

Now you can see the all the 'platform' module manual pages. Press the 'spacebar' to see the next page or the 'q' key to return to the '>>>' prompt.

I've used the 'platform' module for these examples, but any valid module name will work.

Visit my Raspberry Pi page for news, reviews, advice and tutorials.

No comments: