Typecast from Enthoughts traits to python native objects -


this seems trivial task, still not find solution.

when using api of enthought.traits , working data types (e.g. integer int), how can typecast these values native python objects within hastraits class. example:

from traits.api import hastraits, int, list class traitsclass(hastraits):     test = int(10)     channel = list(range(0,test)) # fails range expects integers 

i tried following within class, both yielding errors

test_int = int(test) test_int = test.get_value() 

someone having quick hint me? lot.

this answer revised question.

initializing list trait @ class declaration time fails because, @ stage, test still trait instance. value need created @ time class instantiated (see previous answer).

instead, should use default initializer channel:

in [22]: traits.api import hastraits, int, list  in [24]: class traitsclass(hastraits):     test = int(10)     channel = list                    def _channel_default(self):         return range(0, self.test)    ....:       in [25]: t=traitsclass()  in [26]: t.channel out[26]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -