add more support for python2 with using 'w' instead of 'x'