The following is an example of how you can write and read from the same temporary file handler in Python.
# Create a temp file to write to
temp_file = tempfile.TemporaryFile()
for doc in docs:
# Write documents to tempfile
temp_file.write(json.dumps(doc, default = dthandler))
# Reset the seeker
temp_file.seek(0)
for line in temp_file.readlines():
print line