Under the hood, Python 2.4 passes inline open arguments to the fopen operating system. Python does some manipulation of the mode string under certain conditions.
if (strcmp(mode, "U") == 0 || strcmp(mode, "rU") == 0) mode = "rb";
So, if you pass uppercase U or rU , it will open the file for binary reading. If you look at the source of GNU libc and according to the MSDN page describing the implementation of Windows fopen , the parameter โ26โ is ignored.
More than one mode pointer (' r ', ' w ' and ' a ') does not work in the mode line. This can be seen by looking at the GNU libc string parsing implementation:
switch (*mode) { case 'r': omode = O_RDONLY; break; case 'w': omode = O_WRONLY; oflags = O_CREAT|O_TRUNC; break; case 'a': omode = O_WRONLY; oflags = O_CREAT|O_APPEND; break; default: __set_errno (EINVAL); return NULL; }
The first character of the mode line searches for one of " r ", " w " or " a ", if it is not one of these characters, an error occurs.
Therefore, when a file is opened as " wua ", it will be open only for writing, created if it does not exist and is not truncated. ' U ' and ' a ' will be ignored.
source share