Mailing List Archive

[issue5061] Inadequate documentation of the built-in function open
New submission from Mitchell Model <mlm@acm.org>:

Documentation of the mode parameter of the built-in function open is
insufficient with respect to what values are acceptable.

(1) Right after the mode table, it states "For binary random access, the
mode 'w+b' opens and truncates the file to 0 bytes, while 'r+b' opens
the file without truncation." This is true of text random access too --
w+ or r+. Furthermore, the possibility of a+, while meaningful, is not
mentioned.

(2) The documentation does not, but should, say that while w/r/a with or
without the plus can appear without a 'b' or 't', a plain 'b' as the
mode valuable raises an error that r/w/a wasn't specified.

(3) The documentation does not, but should, say that + cannot stand on
its own -- the mode must also include an r, w, or a. The table listing
the meanings of each value just says + means "open a disk file for
updating (reading and writing)". Suggested rewording is to put the
phrase "in conjunction with 'r', 'w', or 'a', open a disk file...".
Alternatively, add a note to that table entry and explain below that the
plus must accompany a r/w/a.

----------
assignee: georg.brandl
components: Documentation
messages: 80549
nosy: MLModel, georg.brandl
severity: normal
status: open
title: Inadequate documentation of the built-in function open
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.0, Python 3.1

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5061>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5061] Inadequate documentation of the built-in function open [ In reply to ]
Mitchell Model <mlm@acm.org> added the comment:

In point (2) I should have written "a plain 'b' or 't'" and "value" not
"valuable". Neither 't' nor 'b' can appear without a r/w/a.

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5061>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5061] Inadequate documentation of the built-in function open [ In reply to ]
David W. Lambert <lambertdw@corning.com> added the comment:

I disagree. You propose to examine the trees but ignore the forest.
The perspective programmer needs to understand what is a file.

----------
nosy: +LambertDW

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5061>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5061] Inadequate documentation of the built-in function open [ In reply to ]
Mitchell Model <mlm@acm.org> added the comment:

>David W. Lambert <lambertdw@corning.com> added the comment:
>
>I disagree. You propose to examine the trees but ignore the forest.
>The perspective programmer needs to understand what is a file.
>

Could you be more specific about what parts of my comments you
disagree with? The current documentation leaves open the possibility
of someone thinking that random access doesn't apply to text files,
getting errors when entering the apparently legal, but in reality
not, 'b', and that '+', 't+', and 'b+' are legal whereas they require
a r, w, or a.

I know this bit of documentation has been stable for years, but in
doing some writing I got tripped up by trying to write an example
using just '+', despite being very knowledgeable about Python. At
that pointI experimented with the various combinations and compared
the reality against the documentation. What I ended up doing is
splitting the table in two and listing the + combinations explicitly:
Text or Binary:
t text
b binary

Read, Write, or Append:
r beginning, read
w beginning, write
a end, write
r+ beginning, read/write
w+ beginning, read/write
a+ end, read/write

--

--- Mitchell

Added file: http://bugs.python.org/file12864/unnamed

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5061>
_______________________________________
[issue5061] Inadequate documentation of the built-in function open [ In reply to ]
David W. Lambert <lambertdw@corning.com> added the comment:

(prospective, not perspective programmer)

Spelling out the possibilities as suggested in Message80563 makes better
sense to me than writing in words the logic handling the mode argument
of the io.open function. (Perhaps there is a clearer implementation
using a dictionary with frozenset keys, but the io module for py3k is
being recast in c, per my understanding.)

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5061>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com