OrdinalConstant

class datastructuretools.OrdinalConstant

An ordinal constant.

Initializes with dimension, value and representation:

>>> Left = datastructuretools.OrdinalConstant('x', -1, 'Left')
>>> Left
Left
>>> Right = datastructuretools.OrdinalConstant('x', 1, 'Right')
>>> Right
Right
>>> Left < Right
True

Comparing like-dimensioned ordinal constants is allowed:

>>> Up = datastructuretools.OrdinalConstant('y', 1, 'Up')
>>> Up
Up
>>> Down = datastructuretools.OrdinalConstant('y', -1, 'Down')
>>> Down
Down
>>> Down < Up
True

Comparing differently dimensioned ordinal constants raises an exception:

>>> import pytest
>>> bool(pytest.raises(Exception, 'Left < Up'))
True

Abjad adds the following constants to Python’s built-in namespace when Abjad is first imported:

  • Left
  • Right
  • Center
  • Up
  • Down
  • Less
  • More
  • Exact

These eight objects can be used as constant values supplied to keywords.

This behavior is similar to built-in True, False and None.

Note

Use == to compare Abjad ordinal constants. Do not use is.

Ordinal constants are immutable.

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadValueObject.AbjadValueObject" [color=1, group=0, label=AbjadValueObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.abctools.AbjadValueObject.AbjadValueObject"; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_datastructuretools { graph [label=datastructuretools]; "abjad.tools.datastructuretools.OrdinalConstant.OrdinalConstant" [color=black, fontcolor=white, group=2, label=<<B>OrdinalConstant</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadValueObject.AbjadValueObject" -> "abjad.tools.datastructuretools.OrdinalConstant.OrdinalConstant"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

__copy__(\*args) Copies Abjad value object.
__eq__(expr) Is true when all initialization values of Abjad value object equal the initialization values of expr.
__format__([format_specification]) Formats Abjad object.
__ge__(other[, NotImplemented]) Return a >= b.
__gt__(other[, NotImplemented]) Return a > b.
__hash__() Hashes Abjad value object.
__le__(other[, NotImplemented]) Return a <= b.
__lt__(expr) Is true when expr is an ordinal with value greater than that of this ordinal constant.
__ne__(expr) Is true when Abjad object does not equal expr.
__new__(class_[, dimension, value, ...])
__repr__() Gets interpreter representation of Abjad object.

Special methods

(AbjadValueObject).__copy__(*args)

Copies Abjad value object.

Returns new Abjad value object.

(AbjadValueObject).__eq__(expr)

Is true when all initialization values of Abjad value object equal the initialization values of expr.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

OrdinalConstant.__ge__(other, NotImplemented=NotImplemented)

Return a >= b. Computed by @total_ordering from (not a < b).

OrdinalConstant.__gt__(other, NotImplemented=NotImplemented)

Return a > b. Computed by @total_ordering from (not a < b) and (a != b).

(AbjadValueObject).__hash__()

Hashes Abjad value object.

Returns integer.

OrdinalConstant.__le__(other, NotImplemented=NotImplemented)

Return a <= b. Computed by @total_ordering from (a < b) or (a == b).

OrdinalConstant.__lt__(expr)

Is true when expr is an ordinal with value greater than that of this ordinal constant. Otherwise false.

Returns true or false.

(AbjadObject).__ne__(expr)

Is true when Abjad object does not equal expr. Otherwise false.

Returns true or false.

static OrdinalConstant.__new__(class_, dimension=None, value=0, representation=None)
(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.