<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_dict(self, strip=None, sep=_sep, deep='ref'):
 """ Return a flat dict view of the object's attributes Useful for: * displaying all attributes * saving to file * exchaning data with non-tofu libraries Parameters strip : int Flag indicating how stripped the object should be Fed to self.strip() sep : str Separator char used for flattening the dict The output dict is flat (i.e.: no nested dict) Keys are created from the keys of nested dict, separated by sep deep: str Flag indicating how to behave when an attribute is itself a tofu object. The associated field in the exported dict can be: - 'ref' : a simple reference to the object - 'copy': a tofu object itself (i.e.: a copy of the original) - 'dict': the tofu object is itself exported as a dict (using also self.to_dict()) Return ------ dout : dict Flat dict containing all the objects attributes """

        if deep not in ['ref','copy','dict']:
            msg = "Arg deep must be a flag in ['ref','copy','dict'] !"
            raise Exception(msg)
        if strip is None:
            strip = self._dstrip['strip']
        if self._dstrip['strip'] != strip:
            self.strip(strip)

        # ---------------------
        # Call class-specific
        dd = self._to_dict()
        # ---------------------
        dd['dId'] = self._get_dId()
        dd['dstrip'] = {'dict':self._dstrip, 'lexcept':None}

        dout = {}
        for k, v in dd.items():
            lexcept_key = v.get('lexcept_key', None)
            try:
                d = flatten_dict(v['dict'],
                                 parent_key='', sep=sep, deep=deep,
                                 lexcept_key=lexcept_key)
            except Exception as err:
                msg = str(err)
                msg += "\nIssue flattening dict %s"%k
                msg += "\n\n\n" + str(v['dict'])
                raise Exception(msg)
            dout[k] = d
        dout = flatten_dict(dout, parent_key='', sep=sep, deep=deep)
        return dout