<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def open(self, mode='read'):
 """Open the file."""

        if self.file:
            self.close()
            raise 'Close file before opening.'

        if mode == 'write':
            self.file = open(self.path, 'w')
        elif mode == 'overwrite':
            # Delete file if exist.
            self.file = open(self.path, 'w+')
        else:
            # Open for reading.
            self.file = open(self.path, 'r')

        self._csv = csv.DictWriter(self.file,
                                   fieldnames=self.fields,
                                   delimiter=',', quotechar='|',
                                   quoting=csv.QUOTE_MINIMAL,
                                   extrasaction='ignore')
        if self.file.tell() == 0:
            self._csv.writeheader()