[Tutor] Print Doc Strings

mike@virtualblue.org mike@virtualblue.org
Tue, 05 Oct 1999 10:49:28 -0400

After trying your loop and then trying to display a __doc__ string it
looks like I'm not dealing with void __doc__ strings correctly.

$ python
Python 1.5.1 (#1, Mar 21 1999, 22:49:36)  [GCC egcs-2.91.66 19990314/Li on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import sys
>>> for name in dir(sys):
...   item = getattr(sys,name)
...   print item.__doc__
Traceback (innermost last):
  File "<stdin>", line 3, in ?
AttributeError: 'None' object has no attribute '__doc__'

>>> dir(sys)
['__doc__', '__name__', '__stderr__', '__stdin__', '__stdout__', 'argv', 'builtin_module_names', 'copyright', 'exc_info', 'exc_type', 'exec_prefix', 'executable', 'exit', 'getrefcount', 'last_traceback', 'last_type', 'last_value', 'maxint', 'modules', 'path', 'platform', 'prefix', 'ps1', 'ps2', 'setcheckinterval', 'setprofile', 'settrace', 'stderr', 'stdin', 'stdout', 'version']
>>> sys.__doc__
>>> print sys.__doc__
>>> sys.path.__doc__
Traceback (innermost last):
  File "<stdin>", line 1, in ?
AttributeError: __doc__
>>> dir(sys.path)
['append', 'count', 'index', 'insert', 'remove', 'reverse', 'sort']
>>> dir(sys.path.append)
['__doc__', '__name__', '__self__']
>>> dir(sys.path.append.__doc__)
>>> print sys.path.append.__doc__