Skip to content

Instantly share code, notes, and snippets.

@rduplain
Created June 3, 2014 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rduplain/e063114479e7470db8d3 to your computer and use it in GitHub Desktop.
Save rduplain/e063114479e7470db8d3 to your computer and use it in GitHub Desktop.
Is stdin a tty? Use this to determine whether to provide prompt or just read stdin for input.
import sys
if sys.stdin.isatty():
print('you are a tty')
else:
print('you are not a tty')
$ python isatty.py 
you are a tty
$ echo foo | python isatty.py 
you are not a tty
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment