Any way to get information from fun objects about their parameters?

Amy G amy-g-art at cox.net
Wed Mar 24 20:47:42 EST 2004


"Kenneth McDonald" <kmmcdonald at wisc.edu> wrote in message
news:slrnc64bcn.2qa.kmmcdonald at g4.gateway.2wire.net...
> For autodocumentation purposes, I'd like to be able to load a module
> and then find out the following information about functions and
> methods defined within it:
>
> 1) Parameter names and order
> 2) Default value, if any, associated with each parameter
> 3) If the *param or **param conventions are used in the
> parameter list.
>
> Reading documentation about function objects, the only
> relevant information I can extract is a tuple representing
> default param values, which is not useful to me.
>
> I know I could probably do this by parsing the module, but
> I would strongly prefer a simpler way. I'd have thought that,
> like docstrings and many other properties, the parameter info
> would also be stored with function objects.
>
> Thanks,
> Ken


Try

for item in inspect.getsource(modname).split('\n'):
    if (item.startswith("def") and item.endswith(":")):
        print item

Seems to work well.





More information about the Python-list mailing list