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. Advertising

  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. Advertising

  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. Advertising

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. Replies:
    1
    Views:
    287
    Terry Reedy
    Sep 27, 2005
  2. black_13
    Replies:
    2
    Views:
    768
  3. Peng Yu
    Replies:
    5
    Views:
    459
    Dave Angel
    Nov 18, 2009
  4. Benjamin Kaplan

    Re: WindowsError is not available on linux?

    Benjamin Kaplan, Nov 18, 2009, in forum: Python
    Replies:
    0
    Views:
    520
    Benjamin Kaplan
    Nov 18, 2009
  5. Chris Angelico
    Replies:
    0
    Views:
    51
    Chris Angelico
    May 13, 2014
Loading...

Share This Page