<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, fname, append=True):
 """ Write detection to csv formatted file. Will append if append==True and file exists :type fname: str :param fname: Full path to file to open and write to. :type append: bool :param append: Set to true to append to an existing file, if True \ and file doesn't exist, will create new file and warn. If False will overwrite old files. """

        mode = 'w'
        if append and os.path.isfile(fname):
            mode = 'a'
        header = '; '.join(['Template name', 'Detection time (UTC)',
                            'Number of channels', 'Channel list',
                            'Detection value', 'Threshold',
                            'Threshold type', 'Input threshold',
                            'Detection type'])
        print_str = "{0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}; {8}\n".format(
            self.template_name, self.detect_time, self.no_chans,
            self.chans, self.detect_val, self.threshold,
            self.threshold_type, self.threshold_input, self.typeofdet)
        with open(fname, mode) as _f:
            _f.write(header + '\n')  # Write a header for the file
            _f.write(print_str)