Re: [Python-Dev] cpython (3.3): Add examples for opener argument of open (#13424).

2 views
Skip to first unread message

Georg Brandl

unread,
Nov 5, 2012, 1:04:34 PM11/5/12
to pytho...@python.org
Am 03.11.2012 22:10, schrieb eric.araujo:
> http://hg.python.org/cpython/rev/17b094c08600
> changeset: 80219:17b094c08600
> branch: 3.3
> parent: 80214:e6d0951f412a
> user: Éric Araujo <mer...@netwok.org>
> date: Sat Nov 03 17:06:52 2012 -0400
> summary:
> Add examples for opener argument of open (#13424).
>
> Patch by Guillaume Pratte.
>
> files:
> Doc/library/functions.rst | 30 +++++++++++++++++++++++++++
> Doc/library/io.rst | 3 ++
> Misc/ACKS | 1 +
> 3 files changed, 34 insertions(+), 0 deletions(-)
>
>
> diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
> --- a/Doc/library/functions.rst
> +++ b/Doc/library/functions.rst
> @@ -935,6 +935,36 @@
> :mod:`os.open` as *opener* results in functionality similar to passing
> ``None``).
>
> + The following example is an alternative implementation for opening files
> + for exclusive writing. If we did not have support for the ``'x'`` mode,
> + we could implement it with this opener::
> +
> + >>> import os
> + >>> def open_exclusive(path, mode):
> + ... return os.open(path, mode | os.O_CREAT | os.O_EXCL)
> + ...
> + >>> filename = 'spam.txt'
> + >>> fp = open(filename, 'w', opener=open_exclusive)
> + >>> fp2 = open(filename, 'w', opener=open_exclusive)
> + Traceback (most recent call last):
> + ...
> + FileExistsError: [Errno 17] File exists: 'spam.txt'
> +
> + This other example uses the :ref:`dir_fd` parameter of the
> + :func:`os.open` function to open a file relative to a given directory::

Please heed your Sphinx warnings: the :ref:`dir_fd` needs a link caption, since
it can't autogenerate one (the dir_fd anchor does not point to a heading).

Georg

_______________________________________________
Python-Dev mailing list
Pytho...@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/dev-python%2Bgarchive-30976%40googlegroups.com

Éric Araujo

unread,
Nov 6, 2012, 10:12:54 AM11/6/12
to pytho...@python.org
Hi,

Le 05/11/2012 13:04, Georg Brandl a écrit :
> Please heed your Sphinx warnings: the :ref:`dir_fd` needs a link caption, since
> it can't autogenerate one (the dir_fd anchor does not point to a heading).

Okay. I hadn’t noticed it because I was using my system sphinx-build
instead of a local one and there were many warnings related (I think) to
pyspecific extensions not found. Will fix (and also simplify the
examples per the reviews I got).

Cheers

Reply all
Reply to author
Forward
0 new messages