codeape.org
using pyblosxom version 1.4.3 01/10/2008 | rss feed




 
[python documentation for newbies]
 
This is (probably) a tip for newbie Python programmers. If you are programming and need documentation for a module, class, method, or function you can always try this. Start a new python interpreter and import the module you want and type help( object ). If the object (everything is objects in python) is correctly documented this will result in that you will get (man page like) help about the object you passed as argument to the help function. This is how the Python library reference (check under built in functions) describes help:
 
help([object]) Invoke the built-in help system. (This function is intended for interactive use.) If no argument is given, the interactive help system starts on the interpreter console. If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any other kind of object, a help page on the object is generated. New in version 2.2.
 
try it:
oscar-no@aserver:~$ python
Python 2.3.4 (#2, Jul  5 2004, 09:15:05)
[GCC 3.3.4 (Debian 1:3.3.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> help(os)
and try this to:
oscar-no@aserver:~$ python
Python 2.3.4 (#2, Jul  5 2004, 09:15:05)
[GCC 3.3.4 (Debian 1:3.3.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> help(os.listdir)
The documentation is retrieved from the __doc__ string. To associate documentation to the __doc__, you only write a string as the first statement of a module, class, method, or function definition:
oscar-no@aserver:~$ python
Python 2.3.4 (#2, Jul  5 2004, 09:15:05)
[GCC 3.3.4 (Debian 1:3.3.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class MyClass:
...     """This is my class"""
...
>>> print MyClass.__doc__
This is my class

 
updated: [ 2005 - 08 - 10 ] [ 21:42 ]

Valid XHTML 1.0! Valid CSS! pyblosxom Steal These Buttons Subscribe with Bloglines