【发布时间】:2015-01-27 10:12:17
【问题描述】:
我有这个代码:
class Sstdout(sys):
def __init__(self,txtctrl):
self.txtctrl = txtctrl
def write(self,string):
self.txtctrl.write('hi '+string)
sys.stdout.write = Sstdout()
os.dup2(some_odj.fileno(), sys.stdout.fileno())
Traceback (most recent call last):
File "for_testing0.py", line 17, in <module>
os.dup2(sock.fileno(), sys.stdout.fileno())
AttributeError: 'Sstdout' object has no attribute 'fileno'
问题是如何正确更改仅 sys.stdout.write 方法?
【问题讨论】:
-
您介意分享完整的日志吗?
-
完成,发布错误
-
你的代码的目的是什么?
-
重定向输出到文件对象。我只更改了问题