|
|
|
|
|
by masklinn
5031 days ago
|
|
Although you can also (and that can be rather neat when e.g. mapping or filtering) use the method as a function, if you get it from the class: f = Foo()
Foo.bar(f)
note that it will typecheck the first argument to ensure it's an instance of `Foo`, it's not a function, it's an unbound method: >>> class Bar(object): pass
...
>>> b = Bar()
>>> b.n = 66
>>> Foo.bar(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method bar() must be called with Foo instance as first argument (got Bar instance instead)
|
|