file.tell problems (1.5.2/Win32)

Holger Jannsen holger at phoenix-edv.netzservice.de
Mon Jul 5 06:42:46 EDT 1999


Hi Greg,


Greg Ewing schrieb:
> 
> Joshua Rosen wrote:
> >
> > This leads me to believe that `append mode' is intended to `append' at the
> > *current* point in the file, which should, for consistency's sake, start at 0.

I think there is the answer: "Some Unix-Systems" properly would append the write-string
directly at the current file position. 

> I just tried an experiment (on Windows) using "a+"
> mode. It seems that f.tell() is telling the truth,
> but the truth is strange.
> 
> What "a"/"a+" modes seem to mean is "open the
> file positioned at 0, but if the first operation
> is a write, go to the end of file before doing

I think even this is `bizarre`!
Because you could 1st work with "read(1)" or readline()
on the file, getting correct fileposition (tell), but then a
write even wouldn't work like expected!;-( It doesn't work!!
Take the test:
Create a small file with e.g. 3 lines a 10 characters.
>>> f=open('test.txt','a+')
>>> f.tell()
0
>>> f.read(12)
'111111111111'
>>> f.write("sssss")
>>> f.tell()
17
>>> f.close()
You won't even see the obviosly written string inside the file!!
I think, here's something wrong!?

> it". Which seems quite bizarre to me - wouldn't
> it be simpler to just go to the end of the
> file on opening?

You've seen: I could even read on a 'a+'-mode-opened file
getting new file-position.
And there are 'some Unix-OSs' that do the IMHO right thing to 
append directly at the current file-position without jumping
to the end of file.

Ciao,
Holger
[Python1.52, WinNT4.0]




More information about the Python-list mailing list