fmeobjects.FMEFeature.getAttribute

FMEFeature.getAttribute(attrName, desiredType, fallback)

Get the value of the named attribute. Null attribute values will be returned as an empty string. Binary blob attributes are returned as bytes.

For list attributes, an example list name could be “adjacentIds”, which would return a list of all the values found for “adjacentIds{0} … adjacentIds{N}”. The function also accepts a “structured list” specification, such as “attrInfo{}.name”, which would return a list of all the values found for “attrInfo{0}.name … attrInfo{N}.name”.

In cases where there is ambiguity between retrieving an attribute value and a list attribute, the attrName should be appended with “{}” in order to retrieve the list (i.e. the attrName “fme_type” should be “fme_type{}”).

A return of None indicates the attribute or list attribute does not exist.

For null attribute values, an empty string will be returned. In order to determine if an attribute is null, use isAttributeNull.

Specifying a desired type will return the attribute value in the type specified. If the attribute value cannot be represented in the desired type, an exception will be raised.

In any cases where this method will fail either by a raised exception or a missing value, the method will return the fallback value if it’s specified.

Parameters:
  • attrName (str) – The name of the attribute to get on the feature.

  • desiredType (type) – (Optional) The desired type for the attribute value to be returned as. Possible values are bool, int, float, str, bytes, bytearray, and list.

  • fallback (bool, int, float, str, bytes, bytearray, list, or None) – (Optional) If specified, this value is returned instead of raising FMEException on conversion failures.

Return type:

bool, int, float, str, bytes, bytearray, list, or None

Returns:

The value of the named attribute.

Raises:

FMEException – An exception is raised if there was a problem in retrieving the attribute value.