__doc__ of current function?

Ksenia Marasanova ksenia at ksenia.nl
Thu Sep 2 06:40:35 EDT 2004


>
> ... can I write a general docOfCurrentFunction() function so that I
> can rewrite it:
>
> def validatePassword(p):
>    'do something'
>    print docOfCurrentFunction()
>

def docOfCurrentFunction():
     import sys
     func_name = sys._getframe(1).f_code.co_name
     return eval(func_name + '.__doc__')

But I hope that a more intelligent way exists than using 'eval' :)


Ksenia.




More information about the Python-list mailing list