有没有一种方法可以在Python中打印,而不会输出stdin的当前内容?
我正在使用select等待来自服务器/客户机的stdin或数据,但是如果我在键入时收到消息,我的当前文本将与收到的消息一起打印。我可能不正确地使用了select,但我需要找到一种方法来维护当前正在键入的内容,而不将其与消息一起输出。我没有尝试过它(因此我可能有点不专业),但可能能够按照您的要求执行。在其页面中,它们显示了两个用于主机和本地打印的片段:有没有一种方法可以在Python中打印,而不会输出stdin的当前内容?,python,Python,我正在使用select等待来自服务器/客户机的stdin或数据,但是如果我在键入时收到消息,我的当前文本将与收到的消息一起打印。我可能不正确地使用了select,但我需要找到一种方法来维护当前正在键入的内容,而不将其与消息一起输出。我没有尝试过它(因此我可能有点不专业),但可能能够按照您的要求执行。在其页面中,它们显示了两个用于主机和本地打印的片段: >>> import rpyc >>> c = rpyc.classic.connect("localhost
>>> import rpyc
>>> c = rpyc.classic.connect("localhost")
>>> c.execute("print 'hi there'") # this will print on the host
>>> import sys
>>> c.modules.sys.stdout = sys.stdout
>>> c.execute("print 'hi here'") # now this will be redirected here
hi here
,或:
给我们看看code@TheBuffED我已经提出了一个可能的解决方案,但我不太确定这是否真的是你需要的。如果你不告诉我,我就删除这篇文章。@armatita谢谢你,有机会我会试试看
>>> c.execute("print 'hi there'") # printed on the server
>>>
>>> with rpyc.classic.redirected_stdio(c):
... c.execute("print 'hi here'") # printed on the client
...
hi here
>>> c.execute("print 'hi there again'") # printed on the server
>>>