
![]() | Make a class with function behavior instead of a pure function |
![]() | The parameters are class attributes |
![]() | Class instances can be called as ordinary functions, now with x and y as the only formal arguments
class F:
def __init__(self, a=1, b=1, c=1):
self.a = a; self.b = b; self.c = c
def __call__(self, x, y): # special method!
return self.a + self.b*x + self.c*y*y
f = F(a=0.5, c=0.01)
# can now call f as
v = f(0.1, 2)
...
gridvalues(f, xcoor, ycoor, somefile)
|