据我所知,sys.stdout
是一个代表终端标准输出的文件。但是,当我尝试使用 sys.stdout.seek 时,无论我给它什么参数,它都会抛出错误:
IOError: [Errno 29] Illegal seek
发生什么事了?我使用的是 TTY 本身,而不是像 xterm 这样的虚拟终端吗?我该如何解决这个问题?
最佳答案
当 stdout 是 TTY 时,它是字符设备并且不可查找,您无法在 TTY 中查找
。与 tell
相同,但未实现:
>>> sys.stdout.tell()
IOError: [Errno 29] Illegal seek
但是,当您将标准流重定向到文件(例如在 shell 中)时:
$ my program > ouput.txt
现在您可以从 stdout 中seek
,stdout 现在是一个文件。
如果您使用的是 Unix,请查看此引用:
Understanding character device (or character special) files 。
关于python - 我无法 sys.stdout.seek,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45354873/