import gzip
import pickle
# writing into file. This will take long time
fp = gzip.open('tfidf.data','wb')
pickle.dump(tfidf,fp)
fp.close()
# read the file
fp = gzip.open('primes.data','rb') #This assumes that tfidf.data is already packed with gzip
tfidf = pickle.load(fp)
fp.close()