Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

WindowsError is not available on linux?

 
 
Peng Yu
Guest
Posts: n/a
 
      11-18-2009
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
 
Reply With Quote
 
 
 
 
Aahz
Guest
Posts: n/a
 
      11-18-2009
In article <(E-Mail Removed)>,
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.


Here's what I told a co-worker to do yesterday:

if os.name == 'nt':
DiskError = (OSError, WindowsError)
else:
DiskError = WindowsError

try:
disk_operation()
except DiskError:
logit()
--
Aahz ((E-Mail Removed)) <*> http://www.pythoncraft.com/

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it." --Brian W. Kernighan
 
Reply With Quote
 
 
 
 
Benjamin Kaplan
Guest
Posts: n/a
 
      11-18-2009
On Wed, Nov 18, 2009 at 2:53 PM, Aahz <(E-Mail Removed)> wrote:
> In article <(E-Mail Removed)>,
> 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.

>
> Here's what I told a co-worker to do yesterday:
>
> if os.name == 'nt':
> * *DiskError = (OSError, WindowsError)
> else:
> * *DiskError = WindowsError
>
> try:
> * *disk_operation()
> except DiskError:
> * *logit()
> --


Shouldn't that be the other way?
if os.name == 'nt':
DiskError = OSError, WindowsError
else :
DiskError = OSError


> Aahz ((E-Mail Removed)) * * * * * <*> * * * * http://www.pythoncraft.com/
>
> "Debugging is twice as hard as writing the code in the first place.
> Therefore, if you write the code as cleverly as possible, you are, by
> definition, not smart enough to debug it." *--Brian W. Kernighan
> --
> http://mail.python.org/mailman/listinfo/python-list
>

 
Reply With Quote
 
exarkun@twistedmatrix.com
Guest
Posts: n/a
 
      11-18-2009
On 07:53 pm, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>In article <(E-Mail Removed)>,
>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.

>
>Here's what I told a co-worker to do yesterday:
>
>if os.name == 'nt':
> DiskError = (OSError, WindowsError)
>else:
> DiskError = WindowsError
>
>try:
> disk_operation()
>except DiskError:
> logit()


This isn't necessary. WindowsError subclasses OSError.

Jean-Paul
 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      11-18-2009


Benjamin Kaplan wrote:
> On Wed, Nov 18, 2009 at 2:53 PM, Aahz <(E-Mail Removed)> wrote:
>
>> In article <(E-Mail Removed)>,
>> 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.
>>>

>> Here's what I told a co-worker to do yesterday:
>>
>> if os.name ='nt':
>> DiskError =OSError, WindowsError)
>> else:
>> DiskError =indowsError
>>
>> try:
>> disk_operation()
>> except DiskError:
>> logit()
>> --
>>

>
> Shouldn't that be the other way?
> if os.name ='nt':
> DiskError =SError, WindowsError
> else :
> DiskError =SError
>
>
>

Doesn't matter. It's not needed anyway, since WindowsError is derived
from OSError. So just use OSError in the except clause.

DaveA

 
Reply With Quote
 
Aahz
Guest
Posts: n/a
 
      11-28-2009
In article <(E-Mail Removed)>,
<(E-Mail Removed)> wrote:
>On 07:53 pm, (E-Mail Removed) wrote:
>>In article <(E-Mail Removed)>,
>>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.

>>
>>Here's what I told a co-worker to do yesterday:
>>
>>if os.name =3D=3D 'nt':
>> DiskError =3D (OSError, WindowsError)
>>else:
>> DiskError =3D WindowsError
>>
>>try:
>> disk_operation()
>>except DiskError:
>> logit()

>
>This isn't necessary. WindowsError subclasses OSError.


Thanks! Much appreciated! (I haven't done much Windows programming in
the past -- and would have preferred to keep it that way.
--
Aahz ((E-Mail Removed)) <*> http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.
 
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
Re: WindowsError is not available on linux? Peng Yu Python 5 11-18-2009 05:08 AM
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