def json_parse(fileobj, decoder=json.JSONDecoder(), buffersize=2048):
""" Small function to parse a file containing JSON objects separated by a new line. This format is used in the live-rundata-xx.json files produces by SMAC.
taken from http://stackoverflow.com/questions/21708192/how-do-i-use-the-json-module-to-read-in-one-json-object-at-a-time/21709058#21709058
"""
buffer = ''
for chunk in iter(functools.partial(fileobj.read, buffersize), ''):
buffer += chunk
buffer = buffer.strip(' \n')
while buffer:
try:
result, index = decoder.raw_decode(buffer)
yield result
buffer = buffer[index:]
except ValueError:
# Not enough data to decode, read more
break
评论列表
文章目录