Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 特征列表未报告添加或删除的项目_Python_Event Handling_Traits_Enthought - Fatal编程技术网

Python 特征列表未报告添加或删除的项目

Python 特征列表未报告添加或删除的项目,python,event-handling,traits,enthought,Python,Event Handling,Traits,Enthought,鉴于 为什么我会得到: from enthought.traits.api import HasTraits, Tuple, Delegate, Trait, Float,Dict,List class Foo(HasTraits): def __init__(self): super(Foo,self).__init__() self.add_trait('node',List) def _node_items_changed(se

鉴于

为什么我会得到:

 from enthought.traits.api import HasTraits, Tuple, Delegate, Trait, Float,Dict,List

 class Foo(HasTraits):
     def __init__(self):
         super(Foo,self).__init__()
         self.add_trait('node',List)
     def _node_items_changed(self,name,old,new):    
         print name
         print old
         print new
>f=Foo()
>>>f.node.append(0)
节点_项
文档上说我应该得到一份添加/删除项目的列表

我错过了什么?这是Windows8上的traits 4.3


谢谢

更改集合整体的值(列表
和更改集合中的成员之间似乎存在区别。追加似乎会更改内的成员(或至少导致相同的通知)。如果将容器的值作为一个整体进行更改,则确实会将更改后的列表作为
new
值:

>>> f = Foo()
>>> f.node.append(0)
node_items
<undefined>
<traits.trait_handlers.TraitListEvent object at 0x05BA8CF0>
从enthund.traits.api导入HasTraits、Tuple、Delegate、Trait、Float、Dict、List
Foo类(HasTraits):
定义初始化(自):
超级(Foo,self)。\uuuu init\uuuuu()
self.add\u trait('节点',列表)
def_节点_已更改(自身、名称、旧、新):
打印(“\u节点\u已更改:%s%s%s”%(名称、str(旧)、str(新)))
def_节点_项_已更改(自身、名称、旧项、新项):
打印(“\u节点\u项目\u更改:%s%s%s”%(名称、str(旧)、str(新)))
f=Foo()
#使用append更改列表成员资格:
f、 node.append(0)
#\u节点\u项目\u更改:节点\u项目
#更改列表本身:
f、 节点=[1,2,3]
#_node_已更改:节点[0][1,2,3]
#更改成员(结果与追加相同):
f、 节点[1]=4
#\u节点\u项目\u更改:节点\u项目
如果您还没有看到此部分,将提供更多信息。请看答案

from enthought.traits.api import HasTraits, Tuple, Delegate, Trait, Float,Dict,List

class Foo(HasTraits):
    def __init__(self):
        super(Foo,self).__init__()
        self.add_trait('node',List)
    def _node_changed(self,name,old,new):
        print("_node_changed: %s %s %s" % (name, str(old), str(new)))
    def _node_items_changed(self,name,old,new):
        print("_node_items_changed: %s %s %s" % (name, str(old), str(new)))

f = Foo()

# change the List membership with append:
f.node.append(0)
# _node_items_changed: node_items <undefined> <traits.trait_handlers.TraitListEvent object at 0x10128af50>

# change the List itself:
f.node = [1,2,3]
# _node_changed: node [0] [1, 2, 3]

# change a member (same result as append):
f.node[1] = 4
# _node_items_changed: node_items <undefined> <traits.trait_handlers.TraitListEvent object at 0x10128af50>