Index: Modules/_fileio.c =================================================================== --- Modules/_fileio.c (révision 68774) +++ Modules/_fileio.c (copie de travail) @@ -315,6 +315,9 @@ goto error; } + if (append) + lseek(self->fd, 0, SEEK_END); + goto done; error: Index: Lib/test/test_io.py =================================================================== --- Lib/test/test_io.py (révision 68774) +++ Lib/test/test_io.py (copie de travail) @@ -233,6 +233,13 @@ else: self.fail("1/0 didn't raise an exception") + def test_with_open(self): + with open(support.TESTFN, "wb") as f: + f.write(b"xxx") + with open(support.TESTFN, "ab") as f: + # issue 5008: f.tell() returns 0 in append mode instead of 3 + self.assertEqual(f.tell(), 3) + def test_destructor(self): record = [] class MyFileIO(io.FileIO):