我正在嘗試將函數的結果寫入stdin。將函數結果寫入stdin
這是代碼:
def testy():
return 'Testy !'
import sys
sys.stdin.write(testy())
而我得到的錯誤是:
Traceback (most recent call last):
File "stdin_test2.py", line 7, in <module>
sys.stdin.write(testy())
io.UnsupportedOperation: not writable
我不能完全肯定,這是做事的正確方法嗎?
你想要做的是什麼? 'stdin'用於讀取輸入,它是以只讀方式打開的。 – 2013-02-24 19:17:29
是的,我知道。我想要做的是通過寫入標準輸入來模擬input()方法的按鍵。 – 2013-02-24 19:19:04
回溯告訴你它不可寫...你讀過了嗎? – 2013-02-24 19:19:23