本文整理匯總了Python中rapidjson.dump方法的典型用法代碼示例。如果您正苦於以下問題:Python rapidjson.dump方法的具體用法?Python rapidjson.dump怎麽用?Python rapidjson.dump使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rapidjson
的用法示例。
在下文中一共展示了rapidjson.dump方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: save
# 需要導入模塊: import rapidjson [as 別名]
# 或者: from rapidjson import dump [as 別名]
def save(self, font, path):
d = self.unstructure(font)
with open(path, 'w') as file:
json.dump(d, file, indent=self._indent)
示例2: dump
# 需要導入模塊: import rapidjson [as 別名]
# 或者: from rapidjson import dump [as 別名]
def dump(obj: object, stream: bytes, *args, **kwargs) -> bytes:
kwargs = add_settings_to_kwargs(kwargs)
return rapidjson.dump(obj, stream, *args, **kwargs)
示例3: compress_claims
# 需要導入模塊: import rapidjson [as 別名]
# 或者: from rapidjson import dump [as 別名]
def compress_claims(claims):
out = io.BytesIO()
with gzip.open(out, mode="wt") as fo:
json.dump(list(squashed_scopes(claims)), fo)
return base64.encodebytes(out.getvalue()).decode()
示例4: to_geojson_file
# 需要導入模塊: import rapidjson [as 別名]
# 或者: from rapidjson import dump [as 別名]
def to_geojson_file(self, filename, crs=None):
"""
Export this query to a GeoJson FeatureCollection file.
Parameters
----------
filename : str
File to save resulting geojson as.
crs : int or str
Optionally give an integer srid, or valid proj4 string to transform output to
"""
with open(filename, "w") as fout:
json.dump(self.to_geojson(crs=crs), fout)
示例5: thread
# 需要導入模塊: import rapidjson [as 別名]
# 或者: from rapidjson import dump [as 別名]
def thread(players, queue_subproc, mode):
"""Handles running of the match loop"""
uuid_ = unique_uuid("matches")
base_agent = pommerman.agents.BaseAgent
env = pommerman.make(
mode,
[base_agent(), base_agent(),
base_agent(), base_agent()])
net, net_end = multiprocessing.Pipe()
queue_subproc.put([net_end, players, uuid_])
obs = env.reset()
record = {
"board": numpy.array(env._board, copy=True).tolist(),
"actions": [],
"mode": str(mode)
}
done = False
while not done:
obs_res = resolve_classes(obs.copy())
turn_id = str(uuid.uuid4())[:5]
try:
obs_bytes = []
for key, value in enumerate(obs_res):
if 10 + key in obs[0]["alive"]:
obs_bytes.append(
gzip.compress(
bytes(
rapidjson.dumps({
"o": value, # o = obs
"i": turn_id, # i = Turn ID
"d": False # d = Dead
}),
"utf8")))
else:
obs_bytes.append(
gzip.compress(
bytes(
rapidjson.dumps({
"d": True # d = Dead
}),
"utf8")))
net.send([
constants.SubprocessCommands.match_next.value, turn_id,
obs_bytes,
len(obs[0]["alive"])
])
act = net.recv()
except:
act = [0, 0, 0, 0]
record["actions"].append(numpy.array(act, copy=True).tolist())
obs, rew, done = env.step(act)[:3]
record["reward"] = rew
env.close()
with open("./matches/" + uuid_ + ".json", "w") as file:
rapidjson.dump(record, file)
net.send([constants.SubprocessCommands.match_end.value, rew])
net.recv()
exit(0)