stdin - seek() issue on Linux.
Terry Reedy
tejarex at yahoo.com
Mon Apr 22 09:56:37 EDT 2002
"Srihari Vijayaraghavan" <no at spam.please> wrote in message
news:WMTw8.46875$uR5.106037 at newsfeeds.bigpond.com...
> Hello,
>
> I am a new-bie python user. I have Python 2.2.1 installed on a Linux
> computer. I get the following error message when I try to seek() in
the
> stdin, like:
> #cat /var/log/messages | python test.py
> (where /var/log/messages is over 1MB in size)
>
> Traceback (most recent call last):
> File "test.py", line 3, in ?
> sys.stdin.seek(-512, 2)
> IOError: [Errno 29] Illegal seek
By 'cat'ting the random access disk file, you turned it into a
forward-access-only stream of bytes. You definitely cannot seek
backwards (and maybe not forward - don't know). Instead, open() the
file and use the resulting file object:
msgs = open("/var/log/messages", 'r')
msgs.seek(-512, 2)
...
Terry J. Reedy
More information about the Python-list
mailing list