On 4/6/12, Karim <kliat...@gmail.com> wrote:
>
> Hello all,
>
>
> I have :
>
>      def foo():
>             print( getattr(foo, 'func_name'))
>
> Where I get the name of the function but I add to give the name of this
> function. Indeed it is not very helpful...
> I checked the globals() but how I can do to get
> globals()['toto'].func_name. This is not more helpful ;o)
>
> If you have any idea to get the caller name inside the caller.
>

The following works, but only on implementations which provide stack frame
support. As the docs kindly point out:

    "...this isn't guaranteed to exist in all implementations of Python."

Example code:


    import inspect
    def foo():
        '''Print my own name.'''
        frame_info = inspect.getframeinfo(inspect.currentframe())
        print(frame_info.function)


    foo()


That said, there's probably a better way to solve whatever bigger problem
you're trying solve.

-Modulok-
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to