Can I piggyback a question? The following has puzzled me for some time. I always get an IOError from these 'open()' statements, so I've stopped checking for the error. (Don't like to do that!) What's wrong with my code? The 'if IOError:' test shown in comments was originally right after the statement with 'open()'.
if __name__ == '__main__':
#get name of input file and open() infobj
infname = sys.argv[1]
print 'infname is: %s' % (sys.argv[1])
infobj = open( infname, 'rU' )
print 'infobj is: %s' % infobj
# 'if IOError:' always evals to True!?!
# if IOError:
# print 'IOError opening file tmp with mode rU.'
# sys.exit( 1)
#get name of output file and open() outfobj
outfname = sys.argv[2]
print 'outfname is: %s' % (sys.argv[2])
outfobj = open( outfname, 'w' )
print 'outfobj is: %s' % outfobj
# if IOError:
# print 'IOError opening file otmp with mode w.'
# sys.exit( 2)