WindowsError is not available on linux?

alex23 wuwei23 at
Wed Nov 18 04:18:21 CET 2009

Peng Yu <pengyu... at> wrote:
> But the document doesn't say shutil need to be imported in order to
> use WindowsError. Shall the document or the code be corrected?

Neither, it's your understanding that needs correction.

Benjamin wasn't trying to say that WindowsError is defined within
shutil, he was showing that it _isn't_ defined within shutil on a non-
Windows machine.

As you're looking in, you should have noticed this at the
very top, just beneath the declaration of the Error exception:

    except NameError:
        WindowsError = None

This looks for the existence of the WindowsError exception - present
only under Windows - and if it's not there it binds the name to None.
You'll notice that the only place it's used in is prefixed
by the test WindowsError is not None...

I think the mention of the exception being raised when a "Windows-
specific error occurs" should make it pretty clear that this is a
Windows-only exception.

More information about the Python-list mailing list