Convert a python 'type' object to a string

前端 未结 5 2000
刺人心
刺人心 2020-12-02 09:00

I\'m wondering how to convert a python \'type\' object into a string using python\'s reflective capabilities.

For example, I\'d like to print the type of an object

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 09:34

    print("My type is %s" % type(someObject)) # the type in python
    

    or...

    print("My type is %s" % type(someObject).__name__) # the object's type (the class you defined)
    

提交回复
热议问题