manual fix of write function for py3 compliance