打印不带模块前缀的类类型

rwo*_*ols 1 python class python-3.x

我有很多类类型(源自type)。当我打印它们时,我得到类似的东西:

...
<class 'Default.new_templates.NewSnippetCommand'>
<class 'Default.new_templates.NewSyntaxCommand'>
<class 'Default.pane.ClosePaneCommand'>
<class 'Default.pane.FocusNeighboringGroup'>
<class 'Default.pane.MoveToNeighboringGroup'>
<class 'Default.pane.NewPaneCommand'>
<class 'Default.pane.SetMaxColumns'>
...
Run Code Online (Sandbox Code Playgroud)

我想打印:

...
NewSnippetCommand
NewSyntaxCommand
ClosePaneCommand
FocusNeighboringGroup
MoveToNeighboringGroup
NewPaneCommand
SetMaxColumns
...
Run Code Online (Sandbox Code Playgroud)

如何获取类名部分并省略模块部分?

Jim*_*ard 5

您可以使用该__name__属性

>>> type(OrderedDict())
<class 'collections.OrderedDict'>
>>> type(OrderedDict()).__name__
'OrderedDict'
Run Code Online (Sandbox Code Playgroud)