[Tutor] How to have the name of a function inside the code of this function?

Steven D'Aprano steve at pearwood.info
Fri Apr 6 12:06:50 CEST 2012


Karim wrote:
> 
> Hello all,
> 
> 
> I have :
> 
>     def foo():
>            print( getattr(foo, 'func_name'))

Why not this?

def foo():
     print 'foo'


You already know the name of the function.

There is no portable way of retrieving the name of the current function from 
within that function.



-- 
Steven



More information about the Tutor mailing list