Message11918
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? ;/ |
|
Date |
User |
Action |
Args |
2018-04-19 15:35:29 | psykiatris | set | messageid: <1524152129.97.0.682650639539.issue2363@psf.upfronthosting.co.za> |
2018-04-19 15:35:29 | psykiatris | set | recipients:
+ psykiatris, fwierzbicki, zyasoft, jeff.allen, santa4nt, amit |
2018-04-19 15:35:29 | psykiatris | link | issue2363 messages |
2018-04-19 15:35:29 | psykiatris | create | |
|