I'm trying to create one behavior of the script on Linux/Mac/Windows machines with Python 2.7.x.
With a little help from this threads:
I can achieve desired results: by pressing any key script will exit.
But maybe there is a better way to do this? Can someone please help me?
Thanks!
#!/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()