On 14/11/12 11:02:45, Tim Golden wrote: > On 14/11/2012 00:33, Ali Akhavan wrote: >> I am trying to open a file in 'w' mode open('file', 'wb'). open() >> will throw with IOError with errno 13 if the file is locked by >> another application or if user does not have permission to open/write >> to the file. > > What version of Python are you using? > >> >> How can I distinguish these two cases ? Namely, if some application >> has the file open or not. > > Can I ask what you expect to do differently in each of those cases? In > other words, if you can't access the file, you can't access it. (Not to > dismiss your question; I just wonder how you're going to handle the > different cases)
It would be nice if he could give specific error messages, e.g. "Can't write %s because it is locked by %s." vs. "Can't write %s because you don't have write access." I can't speak for Ali, but I'm always annoyed by error messages listing several possible cuases, such as "Can't delete file, because the source or destination is in use". -- HansM -- http://mail.python.org/mailman/listinfo/python-list