3 ms·
Reading top comments might make someone feel that this article is not worth reading, but I encourage people to actually read it. Personally I find it really int
by amardeep 5y ago
Reading top comments might make someone feel that this article is not worth reading, but I encourage people to actually read it. Personally I find it really interesting.
For eg. reading about prebound methods here:
https://python-patterns.guide/python/prebound-methods/ https://python-patterns.guide/python/prebound-methods/. Seasoned python programmers probably wouldn't find anything interesting there, but for me, it was quite useful including instances of where it is being done in python standard library and discussion around when and when shouldn't it be used.
- e19293001 5y agoI agree. The information is interesting to read and it is well written.
- Spivak 5y agoBound methods in Python are one of the keys to enlightenment to understanding its object system -- that self isn't magic and you could implement it yourself (for example having instance methods take a self, and cls parameter) if you wanted. One fun exercise is implementing an object that can "adopt" loose functions. def some_random_function(self) print(self.internal_state) ... mymagicobject.func = some_random_func mymagicobject.func() # -> prints the internal state of the object