WindowsError is not available on linux?

Dave Angel davea at
Wed Nov 18 06:08:18 CET 2009

Peng Yu wrote:
> On Tue, Nov 17, 2009 at 9:18 PM, alex23 <wuwei23 at> wrote:
>> 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:
>>    try:
>>        WindowsError
>>    except NameError:
>>        WindowsError =one
>> 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.
> 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.
Worse, even if the exception cannot be thrown on a non-Windows 
environment, leaving it undefined makes it very awkward to write 
portable code.  An except clause that can never happen in a particular 
environment is pretty innocent.  Or somebody can use a base class for 
his except clause, to catch this error and other related ones.  But it 
blows up if you explicitly use this exception.  I think that needs 
documentation, at a minimum.


More information about the Python-list mailing list