<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def tofile(self, path='filters'):
 r"""Save filter values to ascii-files. Store the filter base and the filter coefficients in separate files in the directory `path`; `path` can be a relative or absolute path. Examples -------- """


        # Get name of filter
        name = self.savename

        # Get absolute path, create if it doesn't exist
        path = os.path.abspath(path)
        os.makedirs(path, exist_ok=True)

        # Save filter base
        basefile = os.path.join(path, name + '_base.txt')
        with open(basefile, 'w') as f:
            self.base.tofile(f, sep="\n")

        # Save filter coefficients
        for val in ['j0', 'j1', 'sin', 'cos']:
            if hasattr(self, val):
                attrfile = os.path.join(path, name + '_' + val + '.txt')
                with open(attrfile, 'w') as f:
                    getattr(self, val).tofile(f, sep="\n")