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.

Title: influences write() when opened with a+ mode
Type: behavior Stage: test needed
Components: Interpreter Core Versions: Python 2.6
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: ajaksu2, amaury.forgeotdarc, georg.brandl, nnorwitz, rudnik_lior, tim.peters
Priority: low Keywords:

Created on 2006-07-12 22:04 by rudnik_lior, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (8)
msg29150 - (view) Author: Lior (rudnik_lior) Date: 2006-07-12 22:04
Python 2.5b1 (r25b1:47027, Jun 20 2006, 09:31:33)

Assuming documentation is correct: (from seek() help
"Note that if the file is opened for appending (mode
'a' or 'a+'), any seek() operations will be undone at
the next write"

Doing the following is __not__ undoing the seek
operation after calling this a few times (Simplified
code snippet):

from __future__ import with_statement
with open(path,'a+') as f:,2) # go to end
    pos = f.tell(),0)
    line = f.readline().strip(),2) # go to end, not effective if opened
with mode a/a+ (currently bug?)

Calling the above code repeatedly didnt increase the
file size beyond 166 bytes (in my code)

msg29151 - (view) Author: Lior (rudnik_lior) Date: 2006-07-12 22:09
Logged In: YES 

Re-tried the code with empty file - it doesnt grow beyond
creating and writting at position 0 so it seems the seek
does influence the write position.
msg29152 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-07-13 06:29
Logged In: YES 

This seems to work for me on Linux.  Maybe we are testing
differently.  What o/s and version are you using?  Does this
work with Python 2.4?  Can you attach a complete test case
that demonstrates this problem?

msg29153 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-07-13 07:43
Logged In: YES 

I also cannot see any problem with the above code and can
append to a file indefinitely. What exactly are you
expecting the code to do, and what do you get? Which OS is this?
msg29154 - (view) Author: Lior (rudnik_lior) Date: 2006-07-28 13:35
Logged In: YES 

This issue is on windows XP.
Wasnt tested on other versions (only 2.5b1 and b2)

I expect the code to always write at the end according to
the documentation. However if I user file seek (opend as A+)
to read from begining of the file, the write also goes to
begining of file.

Note - in the code snippet, please remove the last,2) to see the problem! (it should have been in a
msg29155 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-07-28 18:54
Logged In: YES 

Perhaps you can try in on Windows, Tim...
msg84506 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-03-30 05:06
Can anyone confirm this for Windows and 2.6? Closing otherwise.
msg86001 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-04-15 21:25
I can't reproduce it with python2.6 on Vista. The newer C runtime 
(msvcr90.dll) probably corrected this.
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43661
2009-04-15 21:25:18amaury.forgeotdarcsetstatus: pending -> closed

nosy: + amaury.forgeotdarc
messages: + msg86001

resolution: out of date
2009-03-30 05:06:50ajaksu2setstatus: open -> pending
priority: normal -> low
type: behavior

title: influelce write() when opened with a+ mode -> influences write() when opened with a+ mode
nosy: + ajaksu2
versions: + Python 2.6, - Python 2.5
messages: + msg84506
stage: test needed
2006-07-12 22:04:18rudnik_liorcreate