Python file does not exist exception

Viewed 21598

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?

3 Answers
Related