Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fd.seek() IOError: [Errno 22] Invalid argument

My Python Interpreter (v2.6.5) raises the above error in the following codepart:

fd = open("some_filename", "r")
fd.seek(-2, os.SEEK_END) #same happens if you exchange the second arg. w/ 2
data=fd.read(2);

last call is fd.seek()

Traceback (most recent call last):
    File "bot.py", line 250, in <module>
        fd.seek(iterator, os.SEEK_END);
IOError: [Errno 22] Invalid argument

The strange thing with this is that the exception occurs just when executing my entire code, not if only the specific part with the file opening. At the runtime of this part of code, the opened file definitely exists, disk is not full, the variable "iterator" contains a correct value like in the first codeblock. What could be my mistake?

Thanks in advance

like image 563
Julian Avatar asked Apr 27 '10 18:04

Julian


1 Answers

From lseek(2):

EINVAL

whence is not one of SEEK_SET, SEEK_CUR, SEEK_END; or the resulting file offset would be negative, or beyond the end of a seekable device.

So double-check the value of iterator.

like image 57
wRAR Avatar answered Oct 16 '22 23:10

wRAR