# HG changeset patch # User Jeff Hammel # Date 1487523832 28800 # Node ID 5a74c7ae19cd93384d15d5c4d5e394680c2f487c # Parent 16200adbd4f01c645aaa4f1dcf8a675118407c15 a useful module; however it does not work; scrapping diff -r 16200adbd4f0 -r 5a74c7ae19cd python/is_interactive.py --- a/python/is_interactive.py Tue Feb 07 10:28:00 2017 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -#!/usr/bin/env python - -""" -illustrates usage of isatty - -Ref: http://www.tutorialspoint.com/python/file_isatty.htm -""" - -import optparse -import os -import sys - -# DOES NOT WORK! :( -# > echo 'foo' | is_interactive.py -# Usage: is_interactive.py [options] - -# is_interactive.py: error: missing input - - -def main(args=sys.argv[1:]): - parser = optparse.OptionParser() - options, args = parser.parse_args(args) - - function = str.upper - - if args: - # take input from command line args - input = ' '.join(args) - elif not sys.stderr.isatty(): - # take input from stdin - input = sys.stdin.read() - else: - # no input! cry! - parser.error("missing input") - - print function(input) - -if __name__ == '__main__': - main()