<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_generator_cost_data(self, file):
 """ Writes generator cost data to file. """

        file.write("\n%%%% generator cost data\n")
        file.write("%%\t1\tstartup\tshutdown\tn\tx1\ty1\t...\txn\tyn\n")
        file.write("%%\t2\tstartup\tshutdown\tn\tc(n-1)\t...\tc0\n")
        file.write("%sgencost = [\n" % self._prefix)

        for generator in self.case.generators:
            n = len(generator.p_cost)
            template = '\t%d\t%g\t%g\t%d'
            for _ in range(n):
                template = '%s\t%%g' % template
            template = '%s;\n' % template

            if generator.pcost_model == PW_LINEAR:
                t = 2
#                cp = [p for p, q in generator.p_cost]
#                cq = [q for p, q in generator.p_cost]
#                c = zip(cp, cq)
                c = [v for pc in generator.p_cost for v in pc]
            elif generator.pcost_model == POLYNOMIAL:
                t = 1
                c = list(generator.p_cost)
            else:
                raise

            vals = [t, generator.c_startup, generator.c_shutdown, n] + c

            file.write(template % tuple(vals))
        file.write("];\n")