[Python] Determine function name from within that function

Discussão em 'Python' iniciado por Stack, Novembro 24, 2025.

  1. Stack

    Stack Membro Participativo

    Is there a way to determine a function's name from within the function?

    def foo():
    print("my name is", __myname__) # <== how do I calculate this at runtime?


    In the example above, the body of foo will somehow access the function name "foo" without hard-coding it. The output would be:

    >>> foo()
    my name is foo

    Continue reading...

Compartilhe esta Página