简体   繁体   中英

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. ? Currently I need to define a.eTest=(0.0001, 60, (False, True)) after the instantiation of a.

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. 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 !!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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