[ python-Bugs-1396471 ] file.tell() returns illegal value on Windows
SourceForge.net
noreply at sourceforge.net
Thu Jan 5 16:34:24 CET 2006
Bugs item #1396471, was opened at 2006-01-04 02:53
Message generated for change (Settings changed) made by birkenfeld
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1396471&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Windows
Group: Python 2.4
Status: Open
Resolution: None
>Priority: 7
Submitted By: Tom Goddard (tom_goddard)
Assigned to: Nobody/Anonymous (nobody)
Summary: file.tell() returns illegal value on Windows
Initial Comment:
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
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1396471&group_id=5470
More information about the Python-bugs-list
mailing list