Learn practical skills, build real-world projects, and advance your career
Updated 5 years ago
import ujson, requests, pickle
from pathlib import Path
MODEL_DIR = "../models"
vectorizer = None #Variable in global name space
model = None #Variable in global name space
Utils
def read_jsonl(file_path):
with Path(file_path).open('r', encoding='utf8') as infile:
for line in infile:
try:
yield ujson.loads(line.strip())
except ValueError:
print("Error in reading a jsonline")
continue
def write_jsonl(file_path, lines):
data = [ujson.dumps(line, escape_forward_slashes=False) for line in lines]
Path(file_path).open('w', encoding='utf8').write('\n'.join(data))