Visit
  www.annedawson.net  for more Computer Science Education resources

 

 

 

Last updated: Saturday 28th February 2009, 11:40 PT by AHD

 

 

 

 

Python Help

 

 

The CSCI120A Course Notes and the CSCI165A Course Resources web pages

contain more information on the use of the Python programming language.

 

 

Introduction

 

Python is installed with its own documentation, which can be accessed from:

 

Start -> Programs -> Python 2.3.4 -> Python Manuals

 

The same documentation can also be directly accessed from the editors IDLE and ConTEXT.

 

Help on all aspects of Python can also be found at Python's home page:

 

http://www.python.org/

 

In addition to these utilities, the Python interpreter comes with its own help system.

When you start up the Python interpreter, you will see a reminder to type "help" for more information:

 

 

 

 

 

Typing help at the Python prompt gives you help on help:

 

 

 

 

 

To get help on Python's objects

 

You can get help on any Python object by typing help(object) at the Python prompt, where object is the name of the object you're interested in.

 

For example, you may be interested in string objects and can get detailed information by typing help(str) at the Python prompt.

 

>>> help(str)

 

This will generate pages of detailed information on the Python's string class (str). To exit the help pages, type q.

 

To enter Python's interactive help system, type help() at the Python prompt:

 

>>> help()

 

The prompt for Python's interactive help system is:

 

help>

 

At the help> prompt you may type in the name of any object to get help on. For example, at the help prompt type str to get help on str.

 

To exit the help pages, type q.

 

To exit the help system, type q.

 

 

 

Set up help on Python's keywords

 

Before you can get help on Python's keywords, you must first download the documentation from www.python.org, then set the environment variable called PYTHONDOCS to the path of the documentation files.

 

 

From this site:

http://docs.python.org/download.html, download the HTML ZIP file to your C:\Python23 folder. You must then set the environment variable PYTHONDOCS  to the path for your documentation.

 

For instance, if you download the documentation files to:

 

C:\Python23\docs\Python-Docs-2.3.4

 

then PYTHONDOCS has to be set to that path. The procedure for setting an environment variable will depend on the type of operating system you use. For Windows XP users, you set the variable from

 

Control Panel -> System

 

If you have an earlier version of Windows such as Windows 98, you will need to update C:\autoexec.bat to include the line:

 

set PYTHONDOCS=C:\Python23\docs\python~1.4

 

Please note: the reason the path is specified as

 

C:\Python23\docs\python~1.4

 

and not

 

C:\Python23\docs\Python-Docs-2.3.4

 

is because Windows 98 doesn't accept long file names in autoexec.bat files, so a truncated version has to be used.

 

DOS truncates:

 

Python-Docs-2.3.4

 

to

 

python~1.4

 

 

To check the DOS folder name for a folder such as

 

C:\Python23\docs\Python-Docs-2.3.4

 

go to a DOS shell and type:

 

cd \python23\docs       (then press Enter key)

 

type:

 

dir                                      (then press Enter key)

 

 

You will then see a directory (folder) listing showing the short name on the left and the long name on the right (see screen shot below). Note that the listing doesn't show the dot between the name PYTHON~1 and the extension 4, but you must supply it as python~1.4 (or PYTHON~1.4) in the autoexec.bat file.

 

 

 

After making saving any changes to the autoexec.bat file you must restart your computer before the changes take effect.

 

 

Incidentally, should you want to be able to invoke the Python interpreter from any folder in a DOS shell you should set the PATH environment variable to the folder which contains the Python interpreter file, python.exe. For default installations of Python 2.3.4, the folder is C:\python23

 

Hence, Windows 98 users should include this line in their autoexec.bat file:

 

PATH=%PATH%;C:\Python23;

 

Users of later Windows operating systems should set the PATH environment variable using:

 

Control Panel -> System

 

 

To get help on Python's keywords

 

Once the PYTHONDOCS environment variable has been set, you will then be able to access help on Python's keywords.

 

This is the full set of Python's keywords:

 

and       del       for       is        raise    
assert    elif      from      lambda    return   
break     else      global    not       try      
class     except    if        or        while    
continue  exec      import    pass      yield    
def       finally   in        print

 

For example, to get help on the keyword print

 

type:

 

help('print')

 

at the Python prompt.

 

If the PYTHONDOCS environment variable has been correctly set, you will see the following screen:

 

 

 

 

If you don't get this screen, Python will remind you to set the environment variable.

 

 

To exit the help pages, type q, or any other key to go to the next help page on the topic.