I am trying to open a file and read from it and if the file is not there, I catch the exception and throw an error to stderr. The code that I have:
for x in l:
try:
f = open(x,'r')
except IOError:
print >> sys.stderr, "No such file" , x
but nothing is being printed to stderr, does open create a new file if the file name doesn't exist or is the problem somewhere else?
open(x, 'r')without enclosing it in a try statement, do you get an error?open('asdfghj'), do you get an error? Assuming you don't have such a file with that name, of course.