我不能 sys.stdout.seek [英] I can't sys.stdout.seek

查看:41
本文介绍了我不能 sys.stdout.seek的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,sys.stdout 是一个代表终端标准输出的文件.但是,当我尝试使用 sys.stdout.seek 时,无论我给它什么参数,它都会引发错误:

IOError: [Errno 29] 非法寻道

这是怎么回事?我使用的是 TTY 本身而不是像 xterm 这样的虚拟终端,这是事实吗?我该如何解决?

解决方案

当 stdout 是一个 TTY 时,它是一个字符设备并且它是不可搜索的,你不能在 TTY 中seek.tell 也一样,它没有实现:

<预><代码>>>>sys.stdout.tell()IOError: [Errno 29] 非法查找

但是,当您将标准流重定向到文件时,例如在 shell 中:

$ 我的程序 >输出.txt

现在你可以从标准输出seek,标准输出现在是一个文件.

如果您使用 Unix,请查看此参考:

了解字符设备(或特殊字符)文件.

From what I know, sys.stdout is a file that represents the stdout of a terminal. However, when I try to use sys.stdout.seek, whatever parameters I give it, it throws an error:

IOError: [Errno 29] Illegal seek

What's going on? Is it the fact that I'm using the TTY itself and not a virtual terminal like xterm? How can I resolve this?

解决方案

When stdout is a TTY it's a character device and it's not seekable, you cannot seek in a TTY. Same for tell, it's not implemented:

>>> sys.stdout.tell()
IOError: [Errno 29] Illegal seek

However, when you redirect standard streams to a file for example in a shell:

$ my program > ouput.txt

Now you can seek from stdout, stdout now is a file.

Please look at this reference if you're working with Unix:

Understanding character device (or character special) files.

这篇关于我不能 sys.stdout.seek的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆