file .seek() under MS-Windows

David LeBlanc whisper at oz.net
Wed Jun 19 19:50:40 EDT 2002


I believe you'll find the base specificer to be 0,1 or 2 and never a
negative number.

Python doc:
seek(offset[, whence])
Set the file's current position, like stdio's fseek(). The whence argument
is optional and defaults to 0 (absolute file positioning); other values are
1 (seek relative to the current position) and 2 (seek relative to the file's
end). There is no return value. Note that if the file is opened for
appending (mode 'a' or 'a+'), any seek() operations will be undone at the
next write. If the file is only opened for writing in append mode (mode
'a'), this method is essentially a no-op, but it remains useful for files
opened in append mode with reading enabled (mode 'a+').

If by chance, you where trying to seek to EOF, then that's seek(2) (offset
from base optional). (N.B. "whence" can be signed, but can not be of a
magnitude to cause seeking before BOF or after EOF (if I recall correctly).)

HTH,

David LeBlanc
Seattle, WA USA

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Frank Schaefer
> Sent: Wednesday, June 19, 2002 14:19
> To: python-list at python.org
> Subject: file .seek() under MS-Windows
>
>
> Hi,
>
> The following code:
>
>
> fh = open("myfile.pot", "r")
>
>
> ...
> fh.seek(-1,1)
> ...
>
> produces an error:
> [IOError 22] Invalid Argument
>
> under MS Windows (XP). It works fine under Unix, though (for years).
>
> I appriciate any help.
>
> Thanks,
>
> Frank.
> --
> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list