Re: WindowsError is not available on linux?

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

  1. Peng Yu

    Peng Yu Guest

    On Tue, Nov 17, 2009 at 8:25 PM, Benjamin Kaplan
    <> wrote:
    > On Tue, Nov 17, 2009 at 9:18 PM, Peng Yu <> 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
     
    Peng Yu, Nov 18, 2009
    #1
    1. Advertising

  2. Peng Yu

    alex23 Guest

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

  3. Peng Yu

    Peng Yu Guest

    On Tue, Nov 17, 2009 at 9:18 PM, alex23 <> wrote:
    > Peng Yu <> 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.
     
    Peng Yu, Nov 18, 2009
    #3
  4. Peng Yu

    alex23 Guest

    Peng Yu <> 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
     
    alex23, Nov 18, 2009
    #4
  5. Peng Yu

    Chris Rebert Guest

    On Tue, Nov 17, 2009 at 7:37 PM, Peng Yu <> wrote:
    > On Tue, Nov 17, 2009 at 9:18 PM, alex23 <> wrote:
    >> Peng Yu <> 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
     
    Chris Rebert, Nov 18, 2009
    #5
  6. Peng Yu

    Dave Angel Guest

    Peng Yu wrote:
    > On Tue, Nov 17, 2009 at 9:18 PM, alex23 <> wrote:
    >
    >> Peng Yu <> 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
     
    Dave Angel, Nov 18, 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:
    559
  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