<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(self):
        '''Write this Scrims commands to its path'''

        if self.path is None:
            raise Exception('Scrim.path is None')

        dirname = os.path.dirname(os.path.abspath(self.path))
        if not os.path.exists(dirname):
            try:
                os.makedirs(dirname)
            except:
                raise OSError('Failed to create root for scrim output.')

        with open(self.path, 'w') as f:
            f.write(self.to_string())