ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Solved it!

def recursive_items(ordered_dict):
    for key, value in ordered_dict.items():
        if type(value) is collections.OrderedDict:
            yield from recursive_items(value)
        else:
            yield (key, value)

def print_headers(record):
    print(','.join([key for key, _ in recursive_items(rosidl_runtime_py.message_to_ordereddict(record))]))

I'd missed the API rosidl_runtime_py.message_to_ordereddict() which gives me the message with names and values in a nested OrderedDict, so I iterate over that to pull out the keys from the leaf nodes.