I'm trying to print out the Brown corpus with a simplified tagset to a file. This is the code I'm using, and its just ending up with a blank file.
import json
import nltk
from nltk.corpus import brown
brown_sents = nltk.corpus.brown.tagged_sents(tagset="universal")
for sent in brown_sents:
with open('brown_corpus.txt', 'a') as outfile:
json.dumps(sent, outfile)
json.dumps()
is meant for returning astr
, not for writing to an open file. Useinstead, and you should be fine.