http://www.un.org。 我认为,在阅读其他答复和评论之后,我找到了真正调整方向的良好办法。 请注意,我假定,你们会知道对终端用户的原始投入。
www.un.org/Depts/DGACM/index_spanish.htm 用户法典(Named some_module.py)
print "running some module with 5 raw_input requests"
for x in range(5):
value = raw_input("This is someone else s code asking its (" + str(x) + ") raw_input: ")
print stdin value: + value
Your Test /strong> (以你喜欢的东西计)
import sys
class MY_STD_IN( object ):
def __init__(self, response_list):
self.std_in_list = response_list
self.std_in_length = len(response_list)
self.index = 0
def readline(self):
value = self.std_in_list[self.index]
print value
if self.index < self.std_in_length -1:
self.index += 1
else:
self.index = 0
return value
predetermined_stdin_responses = [ Value 1
, Value 2
, Value 3
]
sys.stdin = MY_STD_IN( predetermined_stdin_responses )
import some_module
www.un.org/Depts/DGACM/index_spanish.htm 浏览Yelds
running some module with 5 raw_input requests
This is someone else s code asking its (0) raw_input: Value 1
stdin value: Value 1
This is someone else s code asking its (1) raw_input: Value 2
stdin value: Value 2
This is someone else s code asking its (2) raw_input: Value 3
stdin value: Value 3
This is someone else s code asking its (3) raw_input: Value 1
stdin value: Value 1
This is someone else s code asking its (4) raw_input: Value 2
stdin value: Value 2
www.un.org/spanish/ecosoc
不是确定你是否重新寻找这种字面答案,而是在这里
import sys
import StringIO
s = StringIO.StringIO("Hello")
sys.stdin = s
a = raw_input("Type something: ")
sys.stdin = sys.__stdin__
print(a+"
You typed in: "+a)
Yields:
类型: Hello
You typed in: Hello