seek() tell()

Peter Hansen peter at engcorp.com
Wed Feb 5 09:14:20 EST 2003


> Enrique Palomo wrote:
> 
> In a script i have wrote:
> ...
>         pi=fo.tell()
>         fo.write(string.join(documento, '\n')+'\n')
>         pf=fo.tell()
>         DICC[c]=[pi, pf]
> ...
> 
> After, by a wxListbox event, you can see only a part of a big file.
> 
> pi works well, but pf-pi is bigger than len(string.join(documento,
> '\n')+'\n')
> 
> Doesn´t it be with the same value??

(Please do not post in HTML.  You should change your settings so
you post only ASCII.)

What value do you expect to get from pf-pi, and what value are
you getting?

I suspect the difference is because you've opened the file in 
"text mode" under Windows.  If you just do fo = open('name', 'w')
it will be in text mode, where all linefeed characters (\n) 
are converted to carriage-return/linefeed pairs, increasing
the size of the output by one byte per line.

If you don't want this behaviour (but under Windows you probably
do), just open the file in "binary mode" using open('name,' 'wb).
For more information, read the friendly manual...

-Peter




More information about the Python-list mailing list