obspy.core.util.misc._yield_obj_parent_attr

_yield_obj_parent_attr(obj, cls=None, is_attr=None, has_attr=None)[source]

Recurse an object, yield a tuple of object, parent, attr.

Can be used, for example, to yield all ResourceIdentifier instances contained in any obspy.core.event class instances and attached instances, as well as the objects they are attached to (parents) and the attribute name in which they are stored (attr).

Parameters:
  • obj The object to recurse through attributes of lists, tuples, and other instances.
  • cls Only return instances of cls if not None, else return all instances.
  • is_attr Only return objects stored as attr_name, if None return all.
  • has_attr Only return objects that have attribute has_attr, if None return all.

General Usage

Get a list of all resource_ids contained in an event, the objects they are attached to, and the attribute name on the parent object.

>>> import obspy
>>> from obspy.core.event import ResourceIdentifier
>>> cat = obspy.read_events()
>>> resource_tuple = list(_yield_obj_parent_attr(cat, ResourceIdentifier))