def write_csv(outfile, data):
    "generate csv output"

    output = []
    headers = []
    keys = ["uu",
            "us",
            "upl",
            "ueid",
            "peid",
            "uipl",
            "pid",
            "pmrp",
            "ptrp",
            "upa",
            "pda",
            "ut",
            ]
        
    for k in keys:
        try:
            headers.append(FIELDS[k]['human'])
        except:
            headers.append(k)

    output.append(headers)

    for record in data:
        line = []
        try:
            for k in keys:
                if record in k:
                    line.append(record[k])
                else:
                    line.append('')
            output.append(line)
        except:
            output.append(['Error parsing line.'])

    writer = csv.writer(outfile, delimiter = ',',
                        quotechar = '"',
                        dialect = 'excel',
                        quoting = csv.QUOTE_ALL)
    writer.writerows(output)
dataset/ETHPy150Open benjaminestes/pyscape-client/pyscape-cli.py/write_csv/swapped operands of `in`