[issue12877] Popen(...).stdout.seek(...) throws Illegal seek
New submission from Jonas H. jo...@lophus.org: from subprocess import Popen, PIPE p = Popen(['ls'], stdout=PIPE) p.wait() p.stdout.seek(0) Traceback (most recent call last): File t.py, line 5, in module p.stdout.seek(0) IOError: [Errno 29] Illegal seek Python 2.7.2, Arch Linux x86-64 (Kernel 3.0) -- messages: 143323 nosy: jonash priority: normal severity: normal status: open title: Popen(...).stdout.seek(...) throws Illegal seek versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12877 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12877] Popen(...).stdout.seek(...) throws Illegal seek
Nadeem Vawda nadeem.va...@gmail.com added the comment: This is expected behaviour - you cannot seek on a pipe. -- nosy: +nadeem.vawda ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12877 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12877] Popen(...).stdout.seek(...) throws Illegal seek
STINNER Victor victor.stin...@haypocalc.com added the comment: stdout is a PIPE. You cannot seek in a PIPE. Write stdout into a file, or use maybe BytesIO or StringIO? -- nosy: +haypo resolution: - invalid status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12877 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12877] Popen(...).stdout.seek(...) throws Illegal seek
Jonas H. jo...@lophus.org added the comment: Why does it have a 'seek' method then? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12877 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12877] Popen(...).stdout.seek(...) throws Illegal seek
STINNER Victor victor.stin...@haypocalc.com added the comment: Why does it have a 'seek' method then? Python doesn't remove a method if the operation is forbidden. For example, Python doesn't remove write() method if the file is read only, and it doesn't remove most methods after close(). I prefer to have files with always the same API. I think that it's more practical. Note: Text files of the io module (TextIOWrapper) raises io.UnsupportedOperation on seek() if the file is not seekable (e.g. if the file is a pipe): $ ~/prog/python/default/python Python 3.3.0a0 (default:d26c7b18fc9d, Jul 22 2011, 12:04:31) import os a,b=os.pipe() f=os.fdopen(a, 'rb') f _io.BufferedReader name=3 f.seek(0) Traceback (most recent call last): File stdin, line 1, in module IOError: [Errno 29] Illegal seek f2=os.fdopen(a, 'r') f2 _io.TextIOWrapper name=3 mode='r' encoding='UTF-8' f2.seek(0) Traceback (most recent call last): File stdin, line 1, in module io.UnsupportedOperation: underlying stream is not seekable -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12877 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com