A question about help() and docstrings

Richard Kuhns rjkuhns at geetel.net
Wed Apr 2 09:24:04 EST 2003


OK, I'm feeling rather dense right now.  I'm obviously not understanding
something, so if anyone would like to hit me with a clue stick please feel
free.

Given a file dummy.py as follows:
====
def dummy_function(one, two):
    """This is a rather stupid function.
    """
    print "1 + 1 = 3"
====

I can run

: molin$/var/tmp; python
Python 2.2.1 (#1, Aug 30 2002, 12:15:30) 
[GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Importing sys and os...
>>> import dummy
>>> help('dummy.dummy_function')
Help on function dummy_function in dummy:

dummy_function(one, two)
    This is a rather stupid function.

>>> 

The doc string shows up just fine.  However, if I use 'from dummy import
*' help() no longer knows anything about it.

: molin$/var/tmp; python
Python 2.2.1 (#1, Aug 30 2002, 12:15:30) 
[GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Importing sys and os...
>>> from dummy import *
>>> help('dummy_function')
no Python documentation found for 'dummy_function'

>>> dir(dummy_function)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__',
'__getattribute__', '__hash__', '__init__', '__name__', '__new__',
'__reduce__', '__repr__', '__setattr__', '__str__', 'func_closure',
'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals',
'func_name']
>>> print dummy_function.__doc__
This is a rather stupid function.
    
>>>

Why doesn't help() work in the second case?
-- 
Richard Kuhns			rjkuhns at geetel.net





More information about the Python-list mailing list