It seems open() is slightly broken in Python 3, in that one cannot open non-seekable files in read-write mode. One such common use is open("/dev/tty", "r+") for interacting directly with the controlling TTY regardless of standard stream redirections. Note that this is a regression for Python 2, where this worked as expected.
What happens is the following:
>>> open("/dev/tty", "r+")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
io.UnsupportedOperation: File or stream is not seekable.
Just for the record, the same thing happens with "w+" and "rb+".
This also means that the getpass module is slightly broken, since it will always fail whenever stdin is redirected. |