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'?

1

1 Answer 1

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__}"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.