<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_metadata(self, f, dsetgrp, data, type_string, options, attributes=None):
 """ Writes an object to file. Writes the metadata for a Python object `data` to file at `name` in h5py.Group `grp`. Metadata is written to HDF5 Attributes. Existing Attributes that are not being used are deleted. .. versionchanged:: 0.2 Arguements changed. Parameters f : h5py.File The HDF5 file handle that is open. dsetgrp : h5py.Dataset or h5py.Group The Dataset or Group object to add metadata to. data The object to write to file. type_string : str or None The type string for `data`. If it is ``None``, one will have to be gotten by ``get_type_string``. options : hdf5storage.core.Options hdf5storage options object. attributes : dict or None, optional The Attributes to set. The keys (``str``) are the names. The values are ``tuple`` of the Attribute kind and the value to set. Valid kinds are ``'string_array'``, ``'string'``, and ``'value'``. The values must correspond to what ``set_attribute_string_array``, ``set_attribute_string`` and ``set_attribute`` would take respectively. Default is no Attributes to set (``None``). Notes ----- The attribute 'Python.Type' is set to the type string. All H5PY Attributes not in ``python_attributes`` and/or ``matlab_attributes`` (depending on the attributes of 'options') are deleted. These are needed functions for writting essentially any Python object, so subclasses should probably call the baseclass's version of this function if they override it and just provide the additional functionality needed. This requires that the names of any additional HDF5 Attributes are put in the appropriate set. See Also -------- utilities.set_attributes_all """

        if attributes is None:
            attributes = dict()
        # Make sure we have a complete type_string.
        if options.store_python_metadata \
                and 'Python.Type' not in attributes:
            attributes['Python.Type'] = \
                ('string', self.get_type_string(data, type_string))
        set_attributes_all(dsetgrp, attributes, discard_others=True)