I’m wondering if there is a difference between
class Test(object):
def __init__(self):
print self.__class__.__name__
and
class Test(object):
def __init__(self):
print type(self).__name__
?
Is there a reason to prefer one or the other?
(In my use case I want to use it to determine the logger name, but I guess this doesn’t matter)
So those two are the same.
I would useself.__class__since it’s more obvious what it is.However,
type(t)won’t work for old-style classes since the type of an instance of an old-style class isinstancewhile the type of a new-style class instance is its class: