[英]functools.partial as IronPython EventHandler
我正在尝试使用IronPython
解释器。 在做教程时,遇到了代理和事件处理程序。 教程做了这样的事情:
from System.IO import FileSystemWatcher
w = FileSystemWatcher()
def handle(*args):
print args
w.Changed += handle
所以我试图聪明并做到这一点:
from System.IO import FileSystemWatcher
from __future__ import print_function
from functools import partial
w = FileSystemWatcher()
w.Changed += partial(print, "Changed: ")
哪个失败了:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Object is not callable.
line 1
是指(交互式会话)中的最后一行
所以IronPython认为partial
对象不可调用,尽管callable(partial(print, "Changed: "))
返回True
通过此解决方法,接受处理程序:
w.Changed += partial(print, "Changed: ").__call__
我的问题:
为什么不接受partial
对象作为事件处理程序。 这是一个错误吗?
这可能不是解决方案,人们可以预期,但是有一个问题,现在开了几年 - https://github.com/IronLanguages/main/issues/808
在.NET版本的2.6.2和2.7b1中不起作用:4.0.30319.1 ipy26 testcase-26482.py
对象不可调用。
ipy27 testcase-26482.py
对象不是callable.py
testcase-26482.py
对象不可调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.