Reputation: 453
I have developed a function which operates on supplied input and if it doesn't find the type of input data as unicode it has to return that input data type unicode is required. I can do it by hard coding it to unicode but in future if I want to change required data type I dont want to change that string accordingly. Therefore I kept required data types of input variables in different file and if it doesn't match, it returns required data type from that file. But it returns something like
Required Data Type - <type 'unicode'>
Instead of <type 'unicode'>
I want it to return just unicode
. Please suggest.
Upvotes: 1
Views: 141
Reputation: 2816
The following is an alternative and works with user-defined classes :
s.__class__.__name__
Example :
class A :
pass
a = A()
type(a).__name__ # 'instance'
a.__class.__name # 'A'
s = u"string"
type(s).__name__ # 'unicode'
s.__class.__name # 'unicode'
Upvotes: 1
Reputation: 251051
Use the __name__
attribute of type:
>>> s = unicode(1)
>>> type(s).__name__
'unicode'
Upvotes: 8