Python tips

Check whether an object has an attribute

hasattr(obj, "name")

Check whether a name exists in local scope

"variable_name" in locals()

Get a safe fallback from a mapping

value = mapping.get("key", default_value)

This is often clearer than manual if key in mapping checks when parsing configuration or metadata.

See also: MOC Computing DevOps and Software, Python