Fix file handling for Python 3.