Help yourself in python

October 31st, 2007 mysurface Posted in Developer, python | Hits: 29323 | 3 Comments »

If your computer science student, you study IT, click with technology, python is not a snake for you. It is a scripting-like programming language that are so famous today. You can type python into google, the first link is not about the reptile but the programming language. There are plenty of apps and scripts written in python, For examples: Miro, a video feed reader; zope, application server; plone, a cms, yum, package manager for red hat, all of them are created using python.

You can use python as a scripting language just like bash, to create something automated, to help you solves some administration routines. I can easily write a hello world example here to illustrate how easy you can hands on.

python -c 'print "hello world"'

Yeah, I am too lazy to put that into a file, so I just do it within command lines.

This post is not made up to promote python, but to share my experience on how to help myself while learning up python. When I was begin to learn python I realized that python can do anything that I can think off, too much until I donno where to start. I keep goggling, searching for ebooks, ask around in IRC channels and later I realized that, python have a very interactive help system that could helps, especially beginners like me who searching for functions, classes and learn up how to make use of them.

Where is the references of python?
The answer is in the python interpreter itself, just type


You are in the interactive interpreter system when you see “>>>” prompt. Now type


Hey, python are ready to serve you. Now you can type keywords to find out python keywords. Don’t use those keywords as your variables and function names. Type topics to list all the programming topics. For examples, if you wanna read about LOOPING, just type LOOPING in the prompt.

Most useful info you can get is from module list, type modules and it will takes sometimes to generate a long list.

How can I search for what module to use?
Just type modules and follow by your keywords, let say I wanna search for statistics info about your operating system, therefore I can type

help> modules stat

Here is a list of matching modules.  Enter any module name to get more help.

commands - Execute shell commands via os.popen() and return status, output.
compiler.future - Parser for future statements
contextlib - Utilities for with-statement contexts.  See PEP 343.
hotshot.stats - Statistics analyzer for HotShot.
sgmllib - A parser for SGML, using the derived class as a static DTD.
stat - Constants/functions for interpreting results of os.stat() and os.lstat().
statvfs - Constants for interpreting the results of os.statvfs() and os.fstatvfs().
xmllib - A parser for XML, using the derived class as static DTD.
rdiff_backup.regress - Code for reverting the rdiff-backup directory to prev state
rdiff_backup.static - MakeStatic and MakeClass
rdiff_backup.statistics - Generate and process aggregated backup information

Oh, I probably want to look into stat method from os.stat(), so I type


Help on built-in function stat in os:

os.stat = stat(...)
    stat(path) -> stat result

    Perform a stat system call on the given path.

Not really helpful, let me just look into entire os class reference.


If you aware of “:”, it now works just like man pages, you can hit SLASH (/) to search for your keywords, arrow keys to navigates. It may not really helpful sometimes, but it helps you to discover keyworks to type into your google search for example codes.

To exit interactive help system, press q enter.

Alternative ways to print some desc of a class, functions.
You can print out os class ‘s descriptions by doing this

import os
print os.__doc__

And you can list all elements an object have in python, objects including package, class, method. Let say you wanna list what os package have, just do this

import os

To exit python interpreter, type


3 Responses to “Help yourself in python”

  1. […] covers here, in case you have any tips, please feel no hesitate to leave me comments. Related PostsHelp yourself in python If your computer science student, you study IT, click with technology, python is not a snake for […]

  2. […] Help yourself in python If your computer science student, you study IT, click with technology, python is not a snake for you. It is a scripting-… […]

  3. Have you thought about including some sort of bookmarking buttons or links on weblog posts?

Leave a Reply