Issue
I saw in the Python documentation for defining an emulating container type https://docs.python.org/3/reference/datamodel.html#emulating-container-types, it states:
object.__len__(self)
Called to implement the built-in function len()...
...object.__getitem__(self, key)
Called to implement evaluation of self[key]. For sequence types ...
...
......
I wonder it seems instructing to add the __len__
function as the attribute of object
class, but if you make a emulating class e.g. EmuList
class EmuList:
def __len__(self):
pass
...
The __len__
function should be attached to EmuList
but object
, although EmuList inherited from object class. What does object
prefix in object.__len__
really mean in this context ?
Solution
I answer my question, actully such "object." is used by Python documentation to express it should be an object's attribute, the examples are below:
Special Attributes The implementation adds a few special read-only attributes to several object types, where they are relevant. Some of these are not reported by the dir() built-in function.
object.dict A dictionary or other mapping object used to store an object’s (writable) attributes.
instance.class The class to which a class instance belongs.
class.bases The tuple of base classes of a class object.
definition.name The name of the class, function, method, descriptor, or generator instance.
definition.qualname The qualified name of the class, function, method, descriptor, or generator instance.
New in version 3.3.
...
the reference is https://docs.python.org/3/library/stdtypes.html#definition.__name__
Answered By - IcyBrk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.