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

  • SEARCH
  • Home
  • 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 7075569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:11:35+00:00 2026-05-28T06:11:35+00:00

Python documentation says that os.rename(src, dst) … On Windows, if dst already exists, OSError

  • 0

Python documentation says that

os.rename(src, dst)

… On Windows, if dst already exists, OSError will be raised even if it is a file …

However, for me it raises WindowsError. Is there a mistake in the documentation?

The second part of the question (more general, but inspired by the problem formulated above):

UPD I am sorry, the second part of the question was incorrect. WindowsError is indeed catched by except OSError as it should.

  • 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. Editorial Team
    Editorial Team
    2026-05-28T06:11:36+00:00Added an answer on May 28, 2026 at 6:11 am

    Since OSError is a superclass of WindowsError, just catch the OSError.

    FWIW, the core devs are free to raise an exception more specific than the minimum promised by the docs.

    Also, the following code works fine for me (Python2.7.2 running on WindowsXP):

    try:
        raise os.rename('nonexisting_file', 'def')
    except OSError:
        print 'caught'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about __class__ in python. The documentation says that __class__ is
The Python documentation for except says: For an except clause with an expression, that
The Python documentation says that sys.path is Initialized from the environment variable PYTHONPATH ,
The Python documentation says that the __init__ method of each class is responsible for
The urllib2 documentation says that timeout parameter was added in Python 2.6. Unfortunately my
In the Python documentation it says: A thread can be flagged as a daemon
The documentation of the Python readline module says Availability: Unix. However, it doesn't appear
The os.walk documentation ( http://docs.python.org/library/os.html ? highlight=os.walk#os.walk), says I can skip traversing unwanted directories
The Python documentation specifies that is is legal to omit the parentheses if a
(I am using python 2.7) The python documentation indicates that you can pass a

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.