[Tutor] Error handling

Michael Lewis mjolewis at gmail.com
Sat Mar 24 23:20:56 CET 2012


Hi everyone,

I am having a bit of trouble understanding what is going on below. What
does the "e" in "except OSError, e:" do?
Any other help you can provide regarding errno would be extremely
appreciated. I've done help() and dir() on it, but I am not really
understanding what's going on with "e.errno != errno.EEXIST:"

Thanks.

import os, errno
try:

    os.makedirs('a/b/c')
except OSError, e:

    if e.errno != errno.EEXIST:

        raise

I am in the process of writing a script to move files from one
directory to another. I am supplying both the source and destination
directories at runtime. I want to create the destination file on the
fly; however, if it already exists, I want to handle that error/ignore
that error. Also, if the the same file exists in both the source and
destination directory, I'd like to override the one in the destination
directory with the one in the source directory.

I am having trouble with the error handling portion. Here is a
pastebin for my source code:

http://pastebin.com/EU578xQs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120324/92383b53/attachment-0001.html>


More information about the Tutor mailing list