0

In Python, I can write

from some_module.some_submodule import SomeClass

foo = SomeClass()
module_and_class = str(type(foo))

and the value of module_and_class is

<class 'some_module.some_submodule.SomeClass'>

How do I get just 'some_module.some_submodule.SomeClass'?

darda
  • 3,597
  • 6
  • 36
  • 49
  • Does this answer your question? [Getting the class name of an instance?](https://stackoverflow.com/q/510972/6045800) – Tomerikoo Aug 02 '21 at 20:46

1 Answers1

3

You want some combination of:

klass = type(foo)

print(klass.__module__, klass.__qualname__)

So, reconstructing it yourself:

module_and_class = f"{klass.__module__}.{klass.__qualname__}"
juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172