D
daishi
Hi,
The following code appears to be doing what I'd expect, but
I'm wondering if someone could confirm that there aren't any
"gotchas" hidden in using methods accessed in this way. In
particular, should I be concerned that in the example below,
f is different from g and h when applying f to instances of
test.Sub? For my simple example things appear reasonable, but ...
Thanks,
Daishi
---test.py
class Super:
def __init__(self):
self.fn = None
def applyFn(self, arg):
if self.fn:
return self.fn(arg)
else:
return "No function defined"
class Sub(Super):
def __init__(self):
self.fn = self.aFn
def aFn(self, x):
return x+2
---Python shell
% python
Python 2.2.3+ (#1, Jul 5 2003, 11:04:18)
[GCC 3.3.1 20030626 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
The following code appears to be doing what I'd expect, but
I'm wondering if someone could confirm that there aren't any
"gotchas" hidden in using methods accessed in this way. In
particular, should I be concerned that in the example below,
f is different from g and h when applying f to instances of
test.Sub? For my simple example things appear reasonable, but ...
Thanks,
Daishi
---test.py
class Super:
def __init__(self):
self.fn = None
def applyFn(self, arg):
if self.fn:
return self.fn(arg)
else:
return "No function defined"
class Sub(Super):
def __init__(self):
self.fn = self.aFn
def aFn(self, x):
return x+2
---Python shell
% python
Python 2.2.3+ (#1, Jul 5 2003, 11:04:18)
[GCC 3.3.1 20030626 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.