An "Object" class?
On 8/27/2019 2:19 PM, Cristian Cocos wrote:
> Thank you! What would be the names of the *class *class,
> and of the *function *class please?
Use type(ob) to get the internal name of the class of an object.
Built-in classes that users may need to call in python code are bound to
the same name in __builtins__, as if __builtins__ were build with class
statements. but many are not.
>>> type(abs) # built-in function
Users can usefully call 'type' but not 'builtin_function_or_method'.
>>> def(f): pass
>>> type(f) # User-defined function.
>>> l = lambda: None # Equivalent lambda expression.
Creating a function by calling 'function' instead of using 'def' or
'lambda' is a super expert endeaver, and the details are CPython
specific and subject to change in any version.
>>> for k, v in vars(list).items(): print(k, type(v))
# 36 lines.
To see super classes of a class, use type.mro(cls). The returned list
always begins with cls and ends with 'object'
>>> mro = type.mro
[<class 'object'>] # As Chris said, baseclass has no superclass.
[<class 'type'>, <class 'object'>]
[<class 'list'>, <class 'object'>]
# Nearly all built-in classes return [cls, 'object'].
[<class 'bool'>, <class 'int'>, <class 'object'>]
# The only exception I can think of.
Terry Jan Reedy