Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 86303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:13:30+00:00 2026-05-10T22:13:30+00:00

On a simple directory creation operation for example, I can make an OSError like

  • 0

On a simple directory creation operation for example, I can make an OSError like this:

(Ubuntu Linux)

>>> import os >>> os.mkdir('foo') >>> os.mkdir('foo') Traceback (most recent call last):   File '<stdin>', line 1, in <module> OSError: [Errno 17] File exists: 'foo' 

Now I can catch that error like this:

>>> import os >>> os.mkdir('foo') >>> try: ...     os.mkdir('foo') ... except OSError, e: ...     print e.args ...  (17, 'File exists') 

Is there a cross-platform way that I can know that that the 17 or the ‘File Exists’ will always mean the same thing so that I can act differently depending on the situation?

(This came up during another question.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:13:30+00:00Added an answer on May 10, 2026 at 10:13 pm

    The errno attribute on the error should be the same on all platforms. You will get WindowsError exceptions on Windows, but since this is a subclass of OSError the same ‘except OSError:‘ block will catch it. Windows does have its own error codes, and these are accessible as .winerror, but the .errno attribute should still be present, and usable in a cross-platform way.

    Symbolic names for the various error codes can be found in the errno module. For example,

    import os, errno try:     os.mkdir('test') except OSError, e:     if e.errno == errno.EEXIST:         # Do something 

    You can also perform the reverse lookup (to find out what code you should be using) with errno.errorcode. That is:

    >>> errno.errorcode[17] 'EEXIST' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can intercept the keystrokes in the PreviewKeyDown event. Set… May 11, 2026 at 10:59 am
  • added an answer You should take a look at the per-pixel collision tutorial… May 11, 2026 at 10:59 am
  • added an answer As far as I am aware no function exists to… May 11, 2026 at 10:59 am

Related Questions

On a simple directory creation operation for example, I can make an OSError like
Based on a simple test I ran, I don't think it's possible to put
I have a simple php script on a server that's using fsockopen to connect
I have a simple form on a view page, implemented as a user control,
I'm working on a simple ASP.Net page (handler, actually) where I check the value
I'm working on a simple multiplayer game in which 2-4 players are placed at
I am working on a simple chat application using a System.Windows.Forms.WebBrowser Control to display
i am working on a simple web app which has a user model and
I'm working on a simple 2D game engine in Java, and having no trouble
I'm working on a simple javascript login for a site, and have come up

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.