This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: File's current position inconsistent with 'a+' mode
Type: behavior Stage:
Components: Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: ebfe, loewis, pitrou
Priority: normal Keywords:

Created on 2009-03-23 08:26 by ebfe, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg83997 - (view) Author: Lukas Lueg (ebfe) Date: 2009-03-23 08:26
The file pointer's behaviour after opening a file in 'a+b' mode is not
consistent among platforms: The pointer is set to the beginning of the
file on Linux and to the end of the file on MacOS. You have to call
.seek(0) before calling .read() to get consistent behaviour on all
platforms.

While this is not a serious problem, it somewhat violates the rule of
least surprise. Also we are not bound to this behaviour and can make
sure that all file objects have their respective positions well-defined
after object-creation.

Thoughts?
msg84025 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-03-23 18:54
The right answer IMO is that the current position should be set to the
end of the file, since it is opened in "append" mode.
What happens actually is that, on some systems, the position is
implicitly set to the end of the file on the first write() rather than
when the file is open()ed.

This should be different in 3.1, could you give it a try?
msg84033 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-03-23 21:01
In 2.x, the mode will do whatever the C library does; this is as it
ought to be. Standard C lets it explicitly implementation-defined
whether the file position pointer is initially at the beginning or at
the end of a file when the file is opened for append. Any write
operating will automatically move the file pointer to the end of the
file; switching between reading and writing must be synchronized with
either a flush operation or a file positioning operation.

So I'm closing this as "won't fix".
History
Date User Action Args
2022-04-11 14:56:46adminsetgithub: 49791
2009-03-23 21:01:25loewissetstatus: open -> closed

nosy: + loewis
messages: + msg84033

resolution: wont fix
2009-03-23 18:54:41pitrousetpriority: normal
type: behavior
versions: + Python 2.7, - Python 2.5
2009-03-23 18:54:19pitrousetnosy: + pitrou
messages: + msg84025
2009-03-23 08:26:22ebfecreate