Custom Search

Wednesday, January 26, 2011

python django howto class name as string

python django how to get class name of an object as string


>>> l = []
>>>
>>> l.__class__.__name__
'list'
===================
>>> t = ()
>>>
>>> t.__class__.__name__
'tuple'
===================
>>> d = {}
>>>
>>> d.__class__.__name__
'dict'
===================
>>> i = int(4)
>>>
>>> i
4
>>> i.__class__.__name__
'int'
===================
>>> f = float(4)
>>>
>>> f
4.0
>>>
>>> f.__class__.__name__
'float'
-------------------------
>>> class Test:
... pass
...
>>>
>>>
>>> t = Test()
>>>
>>> t.__class__.__name__
'Test'
===================

No comments:

Post a Comment