title: python dynamically answer yes/no to terminal prompt
body: <h3>prompt question generator</h3>
  <pre><code>class SynthesisPromptGenerator:
      def wait_key(self):
          ''' Wait for a key press on the console and return it. '''
          result = None
  
          for singlePrompt in [&quot;questionCat&quot;, &quot;questionDog&quot;]:
              try:
                  result = raw_input(singlePrompt)
                  print 'input is: ', result
              except IOError:
                  pass
  
          return result
  </code></pre>
  <p>I have a PromptGenerator that will generate multiple terminal prompt questions, and after answering first question, then second will pop up, as</p>
  <pre><code>questionCat
  (and wait for keyboard input)
  
  questionDog
  (and wait for keyboard input)
  </code></pre>
  <h3>my goal is to automatically and dynamically answer to the questions</h3>
  <pre><code>class PromptResponder:
      def respond(self):
          generator = SynthesisPromptGenerator()
          child = pexpect.spawn(generator.wait_key())
  
          child.expect(&quot;\*Cat\*&quot;)
          child.sendline(&quot;yes&quot;)
          child.expect(&quot;\*Dog\*&quot;)
          child.sendline(&quot;no&quot;)
          child.expect(pexpect.EOF)
  
  
  if __name__ == &quot;__main__&quot;:
      responder = PromptResponder()
      responder.respond()
  </code></pre>
  <ul>
  <li>if the prompt question contains <code>Cat</code> then answer <code>yes</code></li>
  <li>if the prompt question contains <code>Dog</code> then answer <code>no</code></li>
  </ul>
  <p>So it comes to:</p>
  <ol>
  <li>how to get the prompt string from terminal and filter based on it?</li>
  <li>how to answer multiple prompt questions in python?</li>
  </ol>
  <p>I did some search but found most questions are for shell script <code>echo yes | ./script</code>, not much doing it <code>in python</code></p>
  <p>thank you very much</p>