Python Forum

Full Version: type of object as a string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i need to get the type of an object as a string, as in [] -> 'list'. does anything already exist for this or do i need to use my own function?

def typestr(obj):
    return str(type(obj)).split("'")[1]
Try
type([]).__name__