Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: WindowsError is not available on linux?

Reply
Thread Tools

Re: WindowsError is not available on linux?

 
 
Peng Yu
Guest
Posts: n/a
 
      11-18-2009
On Tue, Nov 17, 2009 at 8:25 PM, Benjamin Kaplan
<(E-Mail Removed)> wrote:
> On Tue, Nov 17, 2009 at 9:18 PM, Peng Yu <(E-Mail Removed)> wrote:
>> It's not clear to me whether WindowsError is available on linux or
>> not, after I read the document. But I see WindowsError in shutil.py.
>> Could you somebody let me know what cause the following error?
>>
>>>>> try:

>> ... * raise WindowsError('WindowsError')
>> ... except WindowsError as e:
>> ... * print e
>> ...
>> Traceback (most recent call last):
>> *File "<stdin>", line 3, in <module>
>> NameError: name 'WindowsError' is not defined
>> --

>
> does this answer your question?
>
> Python 2.6.4 (r264:75706, Oct 28 2009, 23:01:00)
> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import shutil
>>>> print shutil.WindowsError

> None


But the document doesn't say shutil need to be imported in order to
use WindowsError. Shall the document or the code be corrected?

http://docs.python.org/library/exceptions.html
 
Reply With Quote
 
 
 
 
alex23
Guest
Posts: n/a
 
      11-18-2009
Peng Yu <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Peng Yu
Guest
Posts: n/a
 
      11-18-2009
On Tue, Nov 17, 2009 at 9:18 PM, alex23 <(E-Mail Removed)> wrote:
> Peng Yu <(E-Mail Removed)> 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.
 
Reply With Quote
 
alex23
Guest
Posts: n/a
 
      11-18-2009
Peng Yu <(E-Mail Removed)> wrote:
> 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.


So file a bug: http://docs.python.org/bugs.html
 
Reply With Quote
 
Chris Rebert
Guest
Posts: n/a
 
      11-18-2009
On Tue, Nov 17, 2009 at 7:37 PM, Peng Yu <(E-Mail Removed)> wrote:
> On Tue, Nov 17, 2009 at 9:18 PM, alex23 <(E-Mail Removed)> wrote:
>> Peng Yu <(E-Mail Removed)> 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.


But your example isn't even Windows-specific because Samba server
exists; any error would network-related or specific to the SMB
protocol rather than Windows-related.

Cheers,
Chris
--
http://blog.rebertia.com
 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      11-18-2009
Peng Yu wrote:
> On Tue, Nov 17, 2009 at 9:18 PM, alex23 <(E-Mail Removed)> wrote:
>
>> Peng Yu <(E-Mail Removed)> 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 =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 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.
>
>

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.

DaveA
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WindowsError is not available on linux? Peng Yu Python 5 11-28-2009 05:40 PM
Re: WindowsError is not available on linux? Benjamin Kaplan Python 0 11-18-2009 03:19 AM
WindowsError: exception: access violation writing 0x00000000 Sparky Python 3 08-04-2009 05:23 PM
WindowsError: [Error 5] Access is denied With _winreg.enum black_13 Python 2 11-28-2007 04:30 PM
WindowsError: stack overflow hardieca@hotmail.com Python 1 09-27-2005 06:52 PM



Advertisments