Python: fixed writting out of memory.