我如何获得一个Python类的名称作为一个string?
我叫什么方法来获得一个class的名字?
In [1]: class test(object): ...: pass ...: In [2]: test.__name__ Out[2]: 'test'  这不是一种方法,而是一个领域。 该字段被称为__name__ 。  class.__name__将以stringforms给出class.__name__的名字。  object.__class__.__name__将会给出一个对象的类的名字。 
 我同意Mr.Shark,但是如果你有一个类的实例,你需要使用它的__class__成员: 
 >>> class test(): ... pass ... >>> a_test = test() >>> >>> a_test.__name__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: test instance has no attribute '__name__' >>> >>> a_test.__class__ <class __main__.test at 0x009EEDE0> 
 在[8]中: str('2'.__class__) 
 出[8]: "<type 'str'>" 
 在[9]中: str(len.__class__) 
 出[9]: "<type 'builtin_function_or_method'>" 
 在[10]中: str(4.6.__class__) 
 出[10]: "<type 'float'>" 
或者如前所述,
 在[11]中: 4.6.__class__.__name__ 
 出[11]: 'float'