Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to get object name?
#1
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?
Quote
#2
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 >>>
bhojendra likes this post
Quote
#3
__qualname__ is what I want. Thanks.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)