JRR
JRR

Reputation: 6152

printing the short name of a class

Is there a way to print the short name of a class without the qualifiers? For instance

c = numbers.Number
print(c??)  # should print Number
c = re.Pattern 
print(c??)  # should print Pattern

I know I can use regex to filter out the unwanted text but I am trying to do this for all classes. So what should I put in place of ???

Upvotes: 3

Views: 150

Answers (1)

Devyl
Devyl

Reputation: 647

print(Number.__name__)
# for object
print(Number().__class__.__name__)

Upvotes: 7

Related Questions