python online help?

Thomas A. Bryan tbryan at python.net
Fri Feb 18 23:19:20 EST 2000


Benyang Tang wrote:
> 
> Is there a online help in python? Say something like
> help print
> would give document of the print command.

Docstrings.  Not all classes/modules/methods have them, but 
many do.

For example, 

>>> import string
>>> print string.__doc__
Common string manipulations.

Public module variables:

whitespace -- a string containing all characters considered whitespace
lowercase -- a string containing all characters considered lowercase letters
uppercase -- a string containing all characters considered uppercase letters
letters -- a string containing all characters considered letters
digits -- a string containing all characters considered decimal digits
hexdigits -- a string containing all characters considered hexadecimal digits
octdigits -- a string containing all characters considered octal digits


>>> print string.find.__doc__ 
find(s, sub [,start [,end]]) -> in

Return the lowest index in s where substring sub is found,
such that sub is contained within s[start,end].  Optional
arguments start and end are interpreted as in slice notation.

Return -1 on failure.
>>> 


When you write your own code, you can include docstrings too:

>>> class Foo:
...   """A class docstring"""
...   def bar(self):
...     """A method docstring"""
...     pass
... 
>>> print Foo.__doc__
A class docstring
>>> f = Foo()
>>> print f.bar.__doc__
A method docstring

---Tom



More information about the Python-list mailing list