cf.AncillaryVariables.getattr

AncillaryVariables.getattr(attr, *default)[source]

Get a named attribute from each element of the list.

fl.getattr(attr, *default) is equivalent to cf.List(for f in fl: getattr(f, attr, *default)).

Parameters :
attr : str

The attribute’s name.

default : optional

When a default argument is given, it is returned when the attribute doesn’t exist; without it, an exception is raised in that case.

Returns :
out : cf.List

Each element’s attribute value.

See also

delattr, hasattr, setattr

Examples

>>> fl.getattr('foo')
['bar1', 'bar2']
>>> del fl[1].foo
>>> fl.getattr('foo', None)
['bar1', None]

Previous topic

cf.AncillaryVariables.flip

Next topic

cf.AncillaryVariables.getprop

This Page