[Python] Getting the module and class of currently executing classmethod in Python

Discussão em 'Python' iniciado por Stack, Outubro 23, 2024.

  1. Stack

    Stack Membro Participativo

    For code that exists in a module named some.module and looks like this:

    class MyClass:

    @classmethod
    def method(cls):
    # do something
    pass


    I'd like to know in the block marked as "do something" what the module name, the class name, and the method name are. In the above example, that would be:

    • module some.module
    • class MyClass
    • method method

    I know of inspect.stack() and I can get the function / method name from it, but I can't find the rest of the data.

    Continue reading...

Compartilhe esta Página