title: Press any key to continue (Python, Crossplatform solution)
body: <p>I'm trying to create one behavior of the script on Linux/Mac/Windows machines with Python 2.7.x. </p>
  
  <p>With a little help from this threads:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/a/7259460/2786370">https://stackoverflow.com/a/7259460/2786370</a></li>
  <li><a href="https://stackoverflow.com/a/11877308/2786370">https://stackoverflow.com/a/11877308/2786370</a> </li>
  </ul>
  
  <p>I can achieve desired results: by pressing any key script will exit. </p>
  
  <p>But maybe there is a better way to do this? Can someone please help me? </p>
  
  <p>Thanks!</p>
  
  <pre><code>#!/usr/bin/env python2.7
  
  import os
  import sys
  
  def wait_for_press():
      if sys.platform == 'win32':
          os.system("pause")
      elif sys.platform in ('linux2', 'darwin'):
          import termios
          import tty
  
          print "Press any key to continue..."
  
          stdin_file_desc = sys.stdin.fileno()
          old_stdin_tty_attr = termios.tcgetattr(stdin_file_desc)
          try:
              tty.setraw(stdin_file_desc)
              sys.stdin.read(1)
          finally:
              termios.tcsetattr(stdin_file_desc, termios.TCSADRAIN, old_stdin_tty_attr)
  
  if __name__ == "__main__":
      wait_for_press()
  </code></pre>