作者folkfook (福)
看板Python
标题[问题] XML资料结构更改时自动通知
时间Fri Jun 29 11:06:58 2007
我想做一个架构是XML记着一堆node, node有些attributes,
每当更改attributes时我想会自动触发callback function或是handler.
test.xml
=================
<monster>
<position x=0 y=0 z=0>
</position>
</monster>
=================
现在我是用lxml.etree来试验:
from lxml import etree
context = etree.parse('test.xml')
position = context.find('//monster/position')
position.set('x', '20') # 就是想在 x 改变时可以notify其他地方
应该怎样写才好? 大家有什麽好的提议?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.148.227.206
2F:→ qrtt1:把要被通知的都注册到 proxy 中 06/29 11:22
3F:→ qrtt1:这念头其实是个(伪) obversation pattern 的实作 XD 06/29 11:23