Python class object definition
I have a question about the Python object class. As far as I understand, all classes are based on the Object class. I cannot find the class definition for the object:
class Object:
code for methods and attributes.
If I use dir (object) I get this:
dir(object)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
Is there any code for these methods or is it not available? I am learning Python with O'Reilly and part of the course is to post a question on the forum and document the answer. I believe I have met all your requirements. I searched the internet for hours and your site. I have also searched for several books. I can't even find this topic. I am relatively new to Python and Object Oriented Programming, so I might be missing something. It may not be necessary to know this to fix the problem, but I'm surprised I can't find any comments on this matter.
source to share
These are internal methods of the type object
. Documentation
the object is the base for all classes. It has methods that are common to all instances of Python classes.
They are usually implemented at runtime, eg. for the CPython interpreter (default implementation) you can find the code at https://github.com/python/cpython/blob/master/Objects/object.c .
You can also check https://github.com/python/cpython/blob/7862ded73723e4573ed5d13488c07b41ac31a07e/Objects/typeobject.c#L4357 where you will find how it object
is defined internally and where different methods are pointed out. Again, these are internal and cpython specific, but will give you a fair idea of ββwhat's going on under the hood.
You can of course override most of these to customize the behavior of your class.
source to share