- 论坛徽章:
- 0
|
本帖最后由 dajuanzi 于 2014-12-02 16:17 编辑
大神们好,小弟学python不久。。。。
class Handler:
def callback(self,prefix,name,*args):
method = getattr(self, prefix+name, None)
if callable(method):return method(*args)
def start(self, name):
self.callback('start_',name)
class HTMLRenderer(Handler)
def start_list(self):
print '<ul>'
以上是处理程序类中的部分代码,对其中 if callable(method):return method(*args)有些不解望大神点拨:
handler= HTMLRenderer()
在调用handler.start('list')就相当于
handler.callback('start_','list') --> method = getattr(self,start_list,None) -->
接下来就不理解了 if callable(method): 这个是真 那么-->return method(*args)
就是说函数handler.callback('start_','list')最终返回结果是 method(*args)...
我知道正确的结果应该是去调用handler.start_list 可是return 的结果却是去调用别的参数(*args)啊method(*args) |
|