file.tell() -- obscure IOError

Uwe Mayer merkosh at hadiko.de
Sat Jun 15 05:17:25 CEST 2002


In article <MPG.1774c753f4d1f6fe989687 at news.rz.uni-karlsruhe.de>, 
merkosh at hadiko.de says...
[...]

now I did it. I isolated a piece of code which produces the same error 
in the command line:

----------------------------------
>>> f = file('test.riff.txt')
>>> f.seek(0,2)
>>> f.tell()
109L
>>> f.seek(0,0)
>>> while f.tell() < 109L:
...   f.read(3)
...
'//d'
'ies'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: (0, 'Error')
>>>
----------------------------------


test.riff.txt contains the following:
--------------------------
//dies ist ein beispielkommentar

hier nichtmehr\r
hier auch nicht //hier schon

und hier ist schluss
//ende
--------------------------

<--- some time later: 5:17 o'clock in the morning --->

i ound the mistake. 
that is: i know what went wrong, but i still don't know why:
f was opened in text mode. calling 
f = file('test.riff.txt','rb')

works fine.
assumingly read() took \r and the new line characters as control 
characters... grml...

Ciao
Uwe



More information about the Python-list mailing list