简体   繁体   English

traits.Tuple对象中traits.Tuple值的初始化

[英]Initialisation of traits.Tuple value in a traits.Tuple object

>>> 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))

How initialise values of a.eTest to (0.0001, 60, (False, True)) concomitantly to the instantiation of a. 如何将a.eTest的值初始化为(0.0001,60,(False,True))与a的实例化。 ? Currently I need to define a.eTest=(0.0001, 60, (False, True)) after the instantiation of a. 当前我需要在实例化a之后定义a.eTest =(0.0001,60,(False,True))。

The devil is in the details ... 细节决定成败 ...

>>> 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))

After trying a lot of things, I noticed that by not specifying a tuple as the first argument, I obtains the wanted result ! 在尝试了很多事情之后,我注意到通过不将元组指定为第一个参数,可以得到想要的结果! I confess that I do not exactly understand all in the traits module. 我承认我不完全了解traits模块中的所有内容。 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 !!! 例如,似乎通过不将元组指定为第一个参数,默认值将是对应特征类型的默认值!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM