Message11918

Author psykiatris
Recipients amit, fwierzbicki, jeff.allen, psykiatris, santa4nt, zyasoft
Date 2018-04-19.15:35:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1524152129.97.0.682650639539.issue2363@psf.upfronthosting.co.za>
In-reply-to
Content
I made the test pass, if I called seek(20) (to read in the text I appended). All other calculations were correct and the test passed. So, I started Jython and saw that if I called readline(), it read the first line of the file. Seeking realitively from what I thought the position would be, it actually started the seek from the END of the file, and not at the byte position of readline().

===============================
>>> f = open('seektest.log', 'wb')
>>> f.write(b'To seek or not to seek,\nThat is the question\n')
>>> f.close()
>>> f = open('seektest.log', 'rb')
>>> f.read()
'To seek or not to seek,\nThat is the question\n'
>>> f.tell()
45L            <--------- length of file
>>> f.readline()
''
>>> f.seek(0)
>>> f.readline()
'To seek or not to seek,\n'
>>> f.tell()
24L       <-------- byte position of first line
>>> f.seek(-10, 1)
>>> f.tell()
35L      <---- started seek from the end of the file, position 45 - 10
>>> f.seek(5, 1)
>>> f.tell()
40L

If I set the position at the start of line 2, it calculates correctly:

>>> f.seek(24)
>>> f.readline()
'That is the question\n'
>>> f.tell()
45L
>>> f.seek(-10, 1)
>>> f.tell()
35L

have I muddied up the issue, or what? ;/
History
Date User Action Args
2018-04-19 15:35:29psykiatrissetmessageid: <1524152129.97.0.682650639539.issue2363@psf.upfronthosting.co.za>
2018-04-19 15:35:29psykiatrissetrecipients: + psykiatris, fwierzbicki, zyasoft, jeff.allen, santa4nt, amit
2018-04-19 15:35:29psykiatrislinkissue2363 messages
2018-04-19 15:35:29psykiatriscreate