• Getty fully qualified class name from class object

    From Ian Pilcher@21:1/5 to All on Tue Aug 22 09:45:05 2023
    How can I programmatically get the fully qualified name of a class from
    its class object? (I'm referring to the name that is shown when str()
    or repr() is called on the class object.)

    Neither the __name__ or __qualname__ class attributes include the
    module. For example:

    >>> import logging

    >>> str(logging.Handler)
    "<class 'logging.Handler'>"

    >>> logging.Handler.__name__
    'Handler'
    >>> logging.Handler.__qualname__
    'Handler'

    How can I programmatically get 'logging.Handler' from the class object?

    --
    ========================================================================
    Google Where SkyNet meets Idiocracy ========================================================================

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Greg Ewing@21:1/5 to Ian Pilcher on Wed Aug 23 04:13:08 2023
    On 23/08/23 2:45 am, Ian Pilcher wrote:
    How can I programmatically get 'logging.Handler' from the class object?

    Classes have a __module__ attribute:

    logging.Handler.__module__
    'logging'

    --
    Greg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ian Pilcher@21:1/5 to Greg Ewing via Python-list on Wed Aug 23 14:05:44 2023
    On 8/22/23 11:13, Greg Ewing via Python-list wrote:
    Classes have a __module__ attribute:

    logging.Handler.__module__
    'logging'

    Not sure why I didn't think to look for such a thing. Looks like it's
    as simple as f'{cls.__module__}.{cls.__qualname__}'.

    Thanks!

    --
    ========================================================================
    Google Where SkyNet meets Idiocracy ========================================================================

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)