Improved Python 3 compatiblity. Now use io.open.

Now use io.open instead of builtin open function.