How special method lookup works?
>>> class B(): ... pass ... >>> class C(object): ... pass ... >>> b = B() >>> b.__len__ = lambda: 7 >>> len(b) 7 >>> c = C() >>> c.__len__ = lambda: 5 >>> len(c) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: object of type 'C' has no len() It is mentioned in Python's documentation, but I still don't understand how it works.
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.