Any way for a function to refer to itself?
Emile van Sebille
emile at fenx.com
Thu Feb 22 23:44:34 EST 2001
I'm not sure if it always plays nice, but you may try
starting with:
>>> def test():
"test function description"
import traceback
me = eval( traceback.extract_stack()[-1][2])
print "DocString: %s functionName: %s " % (me.__doc__,
me.__name__)
>>> test()
DocString: test function description functionName: test
HTH
--
Emile van Sebille
emile at fenx.com
-------------------
"Lee, Rick" <rickylee at americasm01.nt.com> wrote in message
news:3A956962.3BBFED86 at americasm01.nt.com...
> I can't find any other way for a function or method to
refer to itself
> than something like the following:
>
> def foo():
> myself = foo # only if foo is global
> mydoc = myself.__doc__
> myname = myself.__name__
>
> So it can be done this way, but:
>
> - only if the function name can actually be accessed from
the current
> name space
> - if the function name changes, that first line inside
this function
> also has to change
>
> Seems to me there should be a more "Pythonic" way of doing
this. Is
> there?
>
More information about the Python-list
mailing list