Is there a function or method that returns the name of a class or class instance? class X(object): pass X.amethod() or X().amethod() should return the string "X". X().__class__ returns "<class '__main__.X'>" which I could parse. Ugh. Or I could use module pyclbr. Ugh**2.