Search code examples
python-2.7enthoughttraitsui

traits difference between writing member as Trait or Trait() ex x=Str or x=Str()


from traits.api import Str
class Foo(HasTraits):
    a=Str
    b=Str()

Is there any behavioral difference between members 'a' and 'b'?

Are trait attributes always instance specific or can they be class members?


Solution

  • There is no difference. MetaHasTraits (the metaclass behind HasTraits) will happily consume either form and implicitly instantiate the former without arguments.

    Trait attributes are always instance attributes, not class attributes.