Read and write from temp file in Python

June 07, 2012

Reading time ~1 minute

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

Running vim-airline with Maximum Awesome

I use [Maximum Awesome](https://github.com/square/maximum-awesome) when I code in [vim](http://www.vim.org/), it's a great starting place...… Continue reading

Quicksort implementation in Python

Published on August 04, 2014

Fibonacci generator in Python

Published on August 04, 2014