RosettaCodeData/Task/File-IO/Python/file-io-3.py
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

20 lines
560 B
Python

import sys
try:
infile = open('input.txt', 'r')
except IOError:
print >> sys.stderr, "Unable to open input.txt for input"
sys.exit(1)
try:
outfile = open('output.txt', 'w')
except IOError:
print >> sys.stderr, "Unable to open output.txt for output"
sys.exit(1)
try: # for finally
try: # for I/O
for line in infile:
outfile.write(line)
except IOError, e:
print >> sys.stderr, "Some I/O Error occurred (reading from input.txt or writing to output.txt)"
finally:
infile.close()
outfile.close()