1

I have a bunch of class types (derived from type). When I print them, I get stuff like:

...
<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'>
...

I would like to print:

...
NewSnippetCommand
NewSyntaxCommand
ClosePaneCommand
FocusNeighboringGroup
MoveToNeighboringGroup
NewPaneCommand
SetMaxColumns
...

How can I get to the class name part and leave out the module part?

2 Answers 2

5

You could use the __name__ attribute:

>>> type(OrderedDict())
<class 'collections.OrderedDict'>
>>> type(OrderedDict()).__name__
'OrderedDict'
Sign up to request clarification or add additional context in comments.

2 Comments

Note that you're on IPython, which has different default display behavior from ordinary Python print or the ordinary interactive mode.
...and you just edited the input prompts to >>>, but the output behavior is still IPython behavior instead of ordinary interactive interpreter behavior.
3

The name of a class is the __name__ attribute:

print(whateverclass.__name__)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.