WindowsError is not available on linux?

Discussion in 'Python' started by Peng Yu, Nov 18, 2009.

  1. Peng Yu

    Peng Yu Guest

    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
     
    Peng Yu, Nov 18, 2009
    #1
    1. Advertisements

  2. Peng Yu

    Aahz Guest

    In article <>,
    Peng Yu <> 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 () <*> 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
     
    Aahz, Nov 18, 2009
    #2
    1. Advertisements

  3. On Wed, Nov 18, 2009 at 2:53 PM, Aahz <> wrote:
    > In article <>,
    > Peng Yu  <> 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 ()           <*>         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
    >
     
    Benjamin Kaplan, Nov 18, 2009
    #3
  4. Peng Yu

    Guest

    On 07:53 pm, wrote:
    >In article <>,
    >Peng Yu <> 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
     
    , Nov 18, 2009
    #4
  5. Peng Yu

    Dave Angel Guest

    Benjamin Kaplan wrote:
    > On Wed, Nov 18, 2009 at 2:53 PM, Aahz <> wrote:
    >
    >> In article <>,
    >> Peng Yu <> 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
     
    Dave Angel, Nov 18, 2009
    #5
  6. Peng Yu

    Aahz Guest

    In article <>,
    <> wrote:
    >On 07:53 pm, wrote:
    >>In article <>,
    >>Peng Yu <> 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 () <*> http://www.pythoncraft.com/

    The best way to get information on Usenet is not to ask a question, but
    to post the wrong information.
     
    Aahz, Nov 28, 2009
    #6
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Natty Gur
    Replies:
    0
    Views:
    2,799
    Natty Gur
    Jun 6, 2004
  2. =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?=
    Replies:
    0
    Views:
    2,630
    =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?=
    Jun 7, 2004
  3. Replies:
    1
    Views:
    356
    Terry Reedy
    Sep 27, 2005
  4. black_13
    Replies:
    2
    Views:
    1,030
  5. Sparky
    Replies:
    3
    Views:
    3,433
    Sparky
    Aug 4, 2009
  6. Peng Yu
    Replies:
    5
    Views:
    647
    Dave Angel
    Nov 18, 2009
  7. Andrew Berg
    Replies:
    8
    Views:
    1,392
    Andrew Berg
    May 27, 2011
  8. Mark Lawrence

    Re: why did the WindowsError occur?

    Mark Lawrence, Sep 5, 2012, in forum: Python
    Replies:
    3
    Views:
    278
    Chris Angelico
    Sep 5, 2012
Loading...