Fix writing on Python 2