获取类型名称作为字符串

gli*_*81g 1 python

我已经开发了一个对提供的输入进行操作的函数,如果它没有找到输入数据的类型作为unicode,它必须返回输入数据类型unicode是必需的.我可以通过将其硬编码为unicode来实现,但是将来如果我想要更改所需的数据类型,我不想相应地更改该字符串.因此,我将输入变量的数据类型保存在不同的文件中,如果不匹配,则返回该文件中所需的数据类型.但它会返回类似的东西

Required Data Type - <type 'unicode'>
Run Code Online (Sandbox Code Playgroud)

而不是<type 'unicode'>我希望它只返回unicode.请建议.

Ash*_*ary 7

使用__name__类型的属性:

>>> s = unicode(1)
>>> type(s).__name__
'unicode'
Run Code Online (Sandbox Code Playgroud)