This is a bit misleading.
open() as mode arg accepts any character, while you pass a valid one i.e.: "w,r,b,+,a".
Thus you can write: open("fname", "w+ANYTHINGYOUWANT").
It will open file as open("fname", "w+").
And open("fname", "rANYTHINGYOUWANT").
will open file as open("fname", "r").
Regarding "U" flag:
In addition to the standard fopen() values mode may be 'U' or 'rU'.
Python is usually built with universal newlines support; supplying 'U'
opens the file as a text file, but lines may be terminated by any of
the following: the Unix end-of-line convention '\n', the Macintosh
convention '\r', or the Windows convention '\r\n'. All of these
external representations are seen as '\n' by the Python program. If
Python is built without universal newlines support a mode with 'U' is
the same as normal text mode. Note that file objects so opened also
have an attribute called newlines which has a value of None (if no
newlines have yet been seen), '\n', '\r', '\r\n', or a tuple
containing all the newline types seen.
As you can read in Python documentation https://docs.python.org/2/library/functions.html#open
EDIT:
D: Specifies a file as temporary. It is deleted when the last file
pointer is closed.
as you can read in @tmr232's link.
The c, n, t, S, R, T, and D mode options are Microsoft extensions for
fopen and _fdopen and should not be used where ANSI portability is
desired
Further update:
I propose to submit the phenomenon as a bug, because opening a file as read only i.e. with flag "r", then allowing to delete after/via closing it adding a single character like "D", even accidentally is a serious security issue, I think.
But, if this has some unavoidable functionality, please inform me.
open('text.txt','rD')for an existing file on Linux does not raise any errors for me, although the file is not deleted when closed. I am really surprised that if true, this behavior is not documented.Uflag is documented though.