Identifing current function

Mel Wilson mwilson at the-wire.com
Thu Jan 22 16:07:44 CET 2004


In article <slrnc0udgf.flo.bignose-hates-spam at iris.polar.local>,
Ben Finney <bignose-hates-spam at and-benfinney-does-too.id.au> wrote:
>On Thu, 22 Jan 2004 02:21:54 GMT, Brian Donovan wrote:
>>   Is there a way to identify the current function. For example:
>>
>> class A:
>>    def B(self):
>>       print current_function_name
>
>Functions, like all objects, have no inherent name.  Names are bound to
>objects; each object can have zero, one or more names bound to it.  None
>of the names has any particular status as "the" name of the object.

   Functions, classes and modules do have a __name__
attribute.  This is often (but not necessarily) the same as
the name the thing goes by in a namespace that knows it.  It
might or might not be the name the O.P. wants.

        Regards.        Mel.



More information about the Python-list mailing list