cfdm.Constructs.key

Constructs.key(default=ValueError())[source]

Return the construct key of the sole metadata construct.

New in version (cfdm): 1.7.0

See also

get, keys, value

Parameters
default: optional

Return the value of the default parameter if there is not exactly one construct.

If set to an Exception instance then it will be raised instead.

Returns
str

The construct key.

Examples

>>> f = cfdm.Field()
>>> c = f.constructs
>>> d = cfdm.DimensionCoordinate(
...     properties={
...         'standard_name': 'latitude', 'units': 'degrees_north'},
...     data=cfdm.Data(range(5))
... )
>>> c._set_construct(d)
'dimensioncoordinate0'
>>> print(c)
Constructs:
{'dimensioncoordinate0': <DimensionCoordinate: latitude(5) degrees_north>}
>>> c.key()
'dimensioncoordinate0'
>>> c.value()
<DimensionCoordinate: latitude(5) degrees_north>