Always Flush Your Python File Object

If you’re running Python on Windows and if you’re dealing with read and writing files, remember to do a file.flush() after a file.write().

On POSIX systems, it seems that the method will automatically commit the changes onto the file. On Windows systems, it’ll add a null character instead of the character that you’re writing into the file.

So remember kids! Do a .flush() after a .write()!

Copyright © 2016 - Benson Lim -