file position *tell()* works different

M-a-S NO-MAIL at hotmail.com
Sat Sep 20 00:15:34 CEST 2003


"Richie Hindle" <richie at entrian.com> wrote in message news:mailman.1063967785.18911.python-list at python.org...
>
> M-a-S, are you sure you saved test_data.txt with Unix line endings?  I
> tested Peter's script under WinXP/Python2.3 as well, and it failed as
> expected (though with slightly different results):
> <......>
> -- 
> Richie Hindle
> richie at entrian.com
>

Oops! Stupid me! With '\n' it behaves really weird. Same values as yours.

Filepointer:   0
Filepointer:   8         (-3 off the right value - M-a-S)
Filepointer:  20        (-2)
Filepointer:  31        (-1)
Filepointer:  50        (-0)

Filepointer:   0
Filepointer:  11
Filepointer:  22
Filepointer:  32
Filepointer:  50

For the file '0123456789\n'*12 it prints:

Filepointer:   0
Filepointer:   0     (-11 off the right value)
Filepointer:  12    (-10)
Filepointer:  24     (-9)
Filepointer:  36     (-8)
Filepointer:  48     (-7)
Filepointer:  60     (-6)
Filepointer:  72     (-5)
Filepointer:  84     (-4)
Filepointer:  96     (-3)
Filepointer: 108    (-2)
Filepointer: 120    (-1)
Filepointer: 132    (-0)

Filepointer:   0
Filepointer:  11
Filepointer:  22
Filepointer:  33
Filepointer:  44
Filepointer:  55
Filepointer:  66
Filepointer:  77
Filepointer:  88
Filepointer:  99
Filepointer: 110
Filepointer: 121
Filepointer: 132

If I add another line, it breakes:

Filepointer:   0
Traceback (most recent call last):
  File "C:\Home\Programming\Python\t\t.py", line 5, in ?
    print 'Filepointer:%4d' %  fp.tell()
IOError: (0, 'Error')

M-a-S






More information about the Python-list mailing list