3 ms·
Some methods but not others. Specifically, I can call built-in methods, but not methods I define. For example: >>> def f(self): ... return self ...
by brudgers 8y ago
Some methods but not others. Specifically, I can call built-in methods, but not methods I define. For example:
>>> def f(self):
... return self
...
>>> (3).f
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'f'
- bakery2k 8y agoYour `f` is not a method, but a top-level function whose first parameter happens to be named `self`. You can't call `f` as a method of any object, because in Python (unlike Ruby) the top-level namespace is unrelated to the namespaces of any classes.
- brudgers 8y agoI don't disagree. I just think it's much worse than that. There is no scope in Python where I can define 'f' to allow '(3).f'. I cannot restrict a function to the domain of Integers using encapsulation. I am forced to put it in some other arbitrary namespace.