Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
type of object as a string
#1
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]
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Try
type([]).__name__
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  declaring object parameters with type JonWayn 2 856 Dec-13-2022, 07:46 PM
Last Post: JonWayn
  reading a table which is of type string saisankalpj 2 926 Dec-03-2022, 11:19 AM
Last Post: saisankalpj
  TypeError: int() argument must be a string, a bytes-like object or a number, not 'Non Anldra12 2 5,105 May-02-2021, 03:45 PM
Last Post: Anldra12
Star Type Error: 'in' object is not callable nman52 3 3,328 May-01-2021, 11:03 PM
Last Post: nman52
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 7,323 Apr-13-2021, 07:50 AM
Last Post: Anldra12
  TypeError: 'type' object is not subscriptable Stef 1 4,440 Aug-28-2020, 03:01 PM
Last Post: Gribouillis
  How to convert a string "<... object at POINTER>" to an object? mandaxyz 5 3,537 Aug-08-2020, 10:44 PM
Last Post: mandaxyz
  isinstance() always return true for object type check Yoki91 2 2,498 Jul-22-2020, 06:52 PM
Last Post: Yoki91
  C-API for Python 3 - Get String from Object mga010 2 3,546 Jun-23-2020, 04:32 PM
Last Post: mga010
  TypeError: __repr__ returned non-string (type dict) shockwave 0 3,150 May-17-2020, 05:56 PM
Last Post: shockwave

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020