def test_european(self): original = ['Politique de Confidentialité', 'Política de Privacidad'] pbj = pbjson.dumps(original) round_trip = pbjson.loads(pbj) self.assertEqual(original, round_trip) with open('temp.pbj', 'wb') as f: f.write(pbj) with open('temp.pbj', 'rb') as f: fpbj = f.read() self.assertEqual(pbj, fpbj) with open('temp.pbj', 'rb') as f: round_trip = pbjson.load(f) self.assertEqual(original, round_trip)
def test_asian(self): original = ['その子は絶えずくすくす笑っていた', 'お役に立てば幸いです。'] pbj = pbjson.dumps(original) round_trip = pbjson.loads(pbj) self.assertEqual(original, round_trip) with open('temp.pbj', 'wb') as f: f.write(pbj) with open('temp.pbj', 'rb') as f: fpbj = f.read() self.assertEqual(pbj, fpbj) with open('temp.pbj', 'rb') as f: round_trip = pbjson.load(f) self.assertEqual(original, round_trip)
import pbjson import time start = time.time() with open("data.jsonb", "rb") as f: data = pbjson.load(f) print(len(data), len(data[0]), time.time() - start)
def load_model(path): f = open(path, 'rb') model = pbjson.load(f) f.close() return model