WindowsError is not available on linux?

Peng Yu pengyu.ut at gmail.com
Tue Nov 17 22:37:07 EST 2009


On Tue, Nov 17, 2009 at 9:18 PM, alex23 <wuwei23 at gmail.com> wrote:
> Peng Yu <pengyu... at gmail.com> 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 shutil.py, you should have noticed this at the
> very top, just beneath the declaration of the Error exception:
>
>    try:
>        WindowsError
>    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 shutil.py 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.

I don't know about others. The wording "Windows-specific error occurs"
was ambiguous to me. It could refers to some errors resulted from
copying (on a linux machine) some files from linux file systems to
windows files systems (via samba, maybe). I recommend to revise the
document a little bit to avoid confusion.



More information about the Python-list mailing list