<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _load(self, tree):
 """ Run a LOAD statement """

        filename = tree.load_file[0]
        if filename[0] in ['"', "'"]:
            filename = unwrap(filename)
        if not os.path.exists(filename):
            raise Exception("No such file %r" % filename)
        batch = self.connection.batch_write(tree.table)
        count = 0
        with batch:
            remainder, ext = os.path.splitext(filename)
            if ext.lower() in [".gz", ".gzip"]:
                ext = os.path.splitext(remainder)[1]
                opened = gzip.open(filename, "rb")
            else:
                opened = open(filename, "r")
            with opened as ifile:
                if ext.lower() == ".csv":
                    reader = csv.DictReader(ifile)
                    for row in reader:
                        batch.put(row)
                        count += 1
                elif ext.lower() == ".json":
                    for row in ifile:
                        batch.put(json.loads(row))
                        count += 1
                else:
                    try:
                        while True:
                            batch.put(pickle.load(ifile))
                            count += 1
                    except EOFError:
                        pass
        return count