Reputation: 45
Given a nested class B
:
class A:
class B:
def __init__(self):
pass
ab = A.B()
How can I get the full name of the class for ab
? I'd expect a result like A.B
.
Upvotes: 2
Views: 1491
Reputation: 160407
You could get the fully qualified name, __qualname__
, of its __class__
:
>>> ab.__class__.__qualname__
'A.B'
Preferably by using type
(which calls __class__
on the instance):
>>> type(ab).__qualname__
Upvotes: 10