[PythonCE] Weird Error

Alan Kennedy pythonce at xhaus.com
Fri Oct 24 10:27:43 EDT 2003


Voidspace wrote:

> Why does python 2.3 on the pocketPC think that 'w' is an invalid IO mode ?

I don't know the solution for sure, but here's a theory.

Microsoft operating systems tend to do character translation on input
and output streams. In python 2.3 on win2k, when writing a text file,
the C runtime libraries translate all '\n' to '\r\n', the DOS
end-of-line terminator. To open a file in text mode, you open with a
mode of either "rt" or "wt".

If one wants to open a file in "binary" mode, where the '\n' to '\r\n'
translation should not be done, then one uses modes 'rb' or 'wb'.

So maybe the mode of 'w' is fine, but the MS runtime library might be
insisting that you specify either binary or text mode. So try

self.outputfile = open(outputpath, 'wt') # or 'wb'

I could be completely wrong though ;-)

And of course, *nix doesn't have these problems, because '\n' stays
represented by a single character in text files. So using modes "w",
"wb" and "wt" should all be equivalant on *nix.

Al.




More information about the PythonCE mailing list