Python Forum

Full Version: How to get object name?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When I print obj it prints something like:

print(type(obj))
# <class 'some.third.party.ObjectName'>
What I want here is to print ObjectName. How can I get it?
class Foo:
    class Bar:
        pass
    
foo = Foo()
bar = Foo.Bar()
print(foo.__class__.__name__)
print(foo.__class__.__qualname__)
print(bar.__class__.__name__)
print(bar.__class__.__qualname__)
Output:
Foo Foo Bar Foo.Bar >>>
__qualname__ is what I want. Thanks.