Functions 'knowing' other functions in a module

gyro gyromagnetic at
Wed Jan 22 19:16:13 CET 2003

I have an application in which it would be useful for functions within 
the module in which they reside to be able to list the other functions 
(and their arguments) in the module.

Currently, I am doing the following:
def _enum_functions():
     import inspect

     me = __import__('mymod')
     efuncs = []

     funcs = inspect.getmembers(me,inspect.isfunction)

     for fname,func in funcs:
         fcode = func.func_code
         if not fname.startswith('_'):
             num_args = fcode.co_argcount
     return efuncs

def do_something_with_function_list():
     efuncs = _enum_functions()


This approach seems very kludgy, especially the __import__('mymod') 
line. Is it necessary to 'self import' the module to carry out this 
task? Any suggestions for a better approach? I'm sure that I'm missing 
something obvious.
Right now, it does not make sense to move the functions into a class, so 
approaches of this nature aren't currently feasible.

On an unrelated note, is it possible to use string interpolation in doc 
strings? I tried a few different approaches to this, none of which 
worked. If this is not possible, what is the reason?



More information about the Python-list mailing list