Hi,
suppose a script of python is waiting for a file from the stdin and none
is given. How can I make the script to stop and, for example, print an
error message?
Sorry for the n00b question and thanks
import sys if sys.stdin.isatty(): print >>sys.stderr, "expected input from stdin" sys.exit(1) sys.stdout.write(sys.stdin.read())
import sys
filename = raw_input("Enter a filename:")
try:
f = open(filename)
except IOError,e:
print >>sys.stderr, e.strerror, e.filename
sys.exit(e.errno)
#do stuff with f
Comment