diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2012-01-14 11:13:06 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2012-01-14 11:13:06 (GMT) |
commit | 87c0bebead75c81748f1b2858c117f49d9d6cabd (patch) | |
tree | f06a467d3e36e6be259f849fd484ddd58ebf7310 | |
parent | 4479577388e737aba228ce8fbb7583add78ce80d (diff) | |
parent | 512d54fea25804f133032579247a3e66309934e4 (diff) | |
download | cpython-87c0bebead75c81748f1b2858c117f49d9d6cabd.zip cpython-87c0bebead75c81748f1b2858c117f49d9d6cabd.tar.gz cpython-87c0bebead75c81748f1b2858c117f49d9d6cabd.tar.bz2 |
merge heads.
-rw-r--r-- | Doc/library/io.rst | 12 | ||||
-rw-r--r-- | Doc/whatsnew/3.3.rst | 5 | ||||
-rw-r--r-- | Lib/_pyio.py | 2 | ||||
-rw-r--r-- | Modules/_io/fileio.c | 6 |
4 files changed, 13 insertions, 12 deletions
diff --git a/Doc/library/io.rst b/Doc/library/io.rst index 82969eb..e1268cb 100644 --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -472,12 +472,12 @@ Raw File I/O to which the resulting :class:`FileIO` object will give access. The *mode* can be ``'r'``, ``'w'``, ``'x'`` or ``'a'`` for reading - (default), writing, creating or appending. The file will be created if it - doesn't exist when opened for writing or appending; it will be truncated - when opened for writing. :exc:`FileExistsError` will be raised if it already - exists when opened for creating. Opening a file for creating implies - writing, so this mode behaves in a similar way to ``'w'``. Add a ``'+'`` to - the mode to allow simultaneous reading and writing. + (default), writing, exclusive creation or appending. The file will be + created if it doesn't exist when opened for writing or appending; it will be + truncated when opened for writing. :exc:`FileExistsError` will be raised if + it already exists when opened for creating. Opening a file for creating + implies writing, so this mode behaves in a similar way to ``'w'``. Add a + ``'+'`` to the mode to allow simultaneous reading and writing. The :meth:`read` (when called with a positive argument), :meth:`readinto` and :meth:`write` methods on this class will only make one system call. diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst index b2909f7..a60e585 100644 --- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -427,8 +427,9 @@ parameter to control parameters of the secure channel. io -- -The :func:`~io.open` function has a new ``'x'`` mode that can be used to create -a new file, and raise a :exc:`FileExistsError` if the file already exists. +The :func:`~io.open` function has a new ``'x'`` mode that can be used to +exclusively create a new file, and raise a :exc:`FileExistsError` if the file +already exists. It is based on the C11 'x' mode to fopen(). (Contributed by David Townshend in :issue:`12760`) diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 6e8f369..f66290f 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -41,7 +41,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, mode is an optional string that specifies the mode in which the file is opened. It defaults to 'r' which means open for reading in text mode. Other common values are 'w' for writing (truncating the file if it already - exists), 'x' for creating and writing to a new file, and 'a' for appending + exists), 'x' for exclusive creation of a new file, and 'a' for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent. (For reading and diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 57cd9aa..a21aa7a 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -1066,9 +1066,9 @@ PyDoc_STRVAR(fileio_doc, "file(name: str[, mode: str][, opener: None]) -> file IO object\n" "\n" "Open a file. The mode can be 'r', 'w', 'x' or 'a' for reading (default),\n" -"writing, creating or appending. The file will be created if it doesn't\n" -"exist when opened for writing or appending; it will be truncated when\n" -"opened for writing. A `FileExistsError` will be raised if it already\n" +"writing, exclusive creation or appending. The file will be created if it\n" +"doesn't exist when opened for writing or appending; it will be truncated\n" +"when opened for writing. A `FileExistsError` will be raised if it already\n" "exists when opened for creating. Opening a file for creating implies\n" "writing so this mode behaves in a similar way to 'w'.Add a '+' to the mode\n" "to allow simultaneous reading and writing. A custom opener can be used by\n" |