I have a list of lists, let's suppose it is:
sentcorpus = [["hello", "how", "are", "you", "?"], ["hello", "I", "'m", "fine"]]
I want to save it in gzip format:
import gzip
import json
with gzip.open('corpus.json.gz', 'wb') as fileh:
fileh.write(json.dumps(sentcorpus).encode("utf8"))
Then it would be logical to read it back like this:
with gzip.open('wbec_corpus.json.gz', 'rb') as fileh:
sentcorpus = json.load(fileh.read().decode("utf8"))
But no:
AttributeError: 'str' object has no attribute 'read'
Instead this one works:
with gzip.open('wbec_corpus.json.gz', 'rb') as fileh:
sentcorpus = json.load(fileh)
Why is fileh a string and not a file handle?