Message27226
The file tell() method returns an illegal value that causes an exception
when passed to seek(). This happens on Windows when a file that
contains unix-style newlines '\n' is opened and read in text mode 'r'.
Below is code that produces the problem on Windows 2.4.2 in an IDLE
shell.
The bug does not occur when using mode 'rU' or 'rb'. But I expect
correct behaviour with mode 'r'. My understanding is that 'rU'
translates line endings to '\n' in the returned string while mode 'r' still
correctly reads the lines using readline(), recognizing all 3 common
endline conventions, but does not translate (ie includes \n\r or \r or \n
in returned string).
The error in the tell() return value depends on how long the file is.
Changing the 'more\n'*10 line in the example code will cause different
incorrect return values.
Previous bug reports have mentioned problems with tell/seek when
using file iterators, the file.next() method and the "for line in file:"
construct. This bug is different and just involves readline() and tell()
with mode 'r'.
Example code tellbug.py follows:
wf = open('testdata', 'wb')
wf.write('01234\n56789\n'+ 'more\n'*10)
wf.close()
f = open('testdata', 'r')
f.readline()
t = f.tell()
print t
f.seek(t)
-------
Running gives:
>>> execfile('tellbug.py')
-5
Traceback (most recent call last):
File "<pyshell#14>", line 1, in -toplevel-
execfile('tellbug.py')
File "tellbug.py", line 9, in -toplevel-
f.seek(t)
IOError: [Errno 22] Invalid argument |
|
Date |
User |
Action |
Args |
2007-08-23 14:37:07 | admin | link | issue1396471 messages |
2007-08-23 14:37:07 | admin | create | |
|