API Reference for Enthought Tool Suite 3.2.0

Ensures that a trait attribute value is a string that satisfied some additional, optional constraints.

The optional constraints include minimum and maximum lengths, and a regular expression that the string must match.

If the value assigned to the trait attribute is a Python numeric type, the TraitString handler first coerces the value to a string. Values of other non-string types result in a TraitError being raised. The handler then makes sure that the resulting string is within the specified length range and that it matches the regular expression.

Example

class Person(HasTraits):
    name = Trait('', TraitString(maxlen=50, regex=r'^[A-Za-z]*$'))

This example defines a Person class with a name attribute, which must be a string of between 0 and 50 characters that consist of only upper and lower case letters.

Inherits from

Attributes

Inherited from base classes

Method summary

Inherited from base classes

Methods

© Copyright 2002-2009 Enthought, Inc.