def write_conll(spacy_doc, filename, encoding=None):
    rows = []
    for j, sent in enumerate(spacy_doc.sents):
        sent_i = sent.start
        sent_id = j + 1
        rows.append('# sent_id {}'.format(sent_id))
        for i, tok in enumerate(sent):
            # HACK...
            if tok.is_space:
                form = ' '
                lemma = ' '
            else:
                form = tok.orth_
                lemma = tok.lemma_
            tok_id = i + 1
            head = tok.head.i - sent_i + 1
            if head == tok_id:
                head = 0
            misc = 'SpaceAfter=No' if not tok.whitespace_ else '_'
            rows.append('\t'.join([str(tok_id), form, lemma, tok.pos_, tok.tag_,
                                   '_', str(head), tok.dep_.lower(), '_', misc]))
        rows.append('')  # sentences must be separated by a single newline
    conll = '\n'.join(rows)
    write_file(conll, filename, mode='wt', encoding=encoding)
This function will prevent Django from serving a Content-Disposition header
dataset/ETHPy150Open chartbeat-labs/textacy/textacy/fileio/write.py/write_conll--crossover with--dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/django/http/utils.py/fix_IE_for_attach