>>> import traits.api as traits
>>> class Foo(traits.HasTraits):
... eTest = traits.Tuple((0.0001, 60, traits.Tuple(traits.Bool(False), traits.Bool(True))))
...
>>> a=Foo()
>>> a.eTest
(0.0001, 60, <traits.trait_types.Tuple object at 0x7fa825fceac8>)
>>> a.eTest=(0.0001, 60, (False, True))
>>> a.eTest
(0.0001, 60, (False, True))如何将a.eTest的值初始化为(0.0001,60,(False,True)),同时实例化一个.?当前我需要在实例化后定义a.eTest=(0.0001,60,(False,True))。
发布于 2018-08-24 20:00:06
魔鬼在细节中。
>>> class Foo(traits.HasTraits):
... eTest = traits.Tuple(0.0001, 60, traits.Tuple(traits.Bool(False), traits.Bool(True)))
...
>>> a=Foo()
>>> a.eTest
(0.0001, 60, (False, True))在尝试了很多方法之后,我注意到通过不指定元组作为第一个参数,我得到了想要的结果!我承认我并不完全理解特征模块中的所有内容。For example it seems that by not specifying a tuple as the first argument, the default values would be the default values for the corresponding trait types !!!
https://stackoverflow.com/questions/51991286
复制相似问题