Range#

class Range(*args, **kwargs)#

Bases: List[T]

Allow to specify a list of items using ranges.

The string must match start:stop[:step]. This will generate values between start and stop, spaced by step. The stop value will be included (if step allows it). step is optional and will default to one. The order of start and stop will dictate if values are ascending or descending.

The trait type must be one of allowed_traits (by default float or int).

"2000:2005": [2000, 2001, 2002, 2003, 2004, 2005]
"2000:2005:2": [2000, 2002, 2004]
"2005:2000:2": [2005, 2003, 2001]
"0.:2.:0.5": [0.0, 0.5, 1.0, 1.5, 2.0]
Parameters:
allowed_traits: list[type[TraitType]] = [<class 'traitlets.traitlets.Float'>, <class 'traitlets.traitlets.Int'>]#

Allowed trait types.

from_string(s)#

Get a value from a config string.

Will test for a string specifying a range.

Parameters:

s (str)

Return type:

list[T] | None

from_string_list(s_list)#

Get a value from a config string.

Will test for a string specifying a range.

Parameters:

s_list (list[str])

Return type:

list[T] | None

generate_range(start_s, stop_s, step_s)#

Get a list of value from a range specification.

Parameters:
  • start_s (str) – Strings parameters found in the range specification. Step cannot be ommited here and must be replaced by a default.

  • stop_s (str) – Strings parameters found in the range specification. Step cannot be ommited here and must be replaced by a default.

  • step_s (str) – Strings parameters found in the range specification. Step cannot be ommited here and must be replaced by a default.

Return type:

list[T]

range_max_len: int = 500#
range_rgx = re.compile('([-+.0-9eE]+?):([-+.0-9eE]+?)(?::([-+.0-9eE]*?))?')#