4 Replies - 503 Views - Last Post: 01 September 2011 - 07:05 AM Rate Topic: -----

#1 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Mistake in Python Docs?

Posted 28 August 2011 - 03:56 AM

Hi, I found the following line as regards the os.copy method at http://docs.python.o....html#os.rename:

Rename the file or directory src to dst. If dst is a directory, OSError will be raised.

However, i am easily able to rename a folder named Cool to Fool using the following command:

import os
os.rename("C:/Cool", "C:/Fool")



and no OSError is being raised. Can someone explain this?

Is This A Good Question/Topic? 0
  • +

Replies To: Mistake in Python Docs?

#2 Brewer  Icon User is offline

  • Awesome
  • member icon

Reputation: 179
  • View blog
  • Posts: 1,044
  • Joined: 14-June 10

Re: Mistake in Python Docs?

Posted 28 August 2011 - 04:16 AM

The doc's aren't incorrect, they just aren't entirely clear. What it is saying is that for os.rename(src, dst) if dst is a folder and src is a file (i.e. test.txt) then an OSError will be raised. Simply renaming one folder with the name of an existing folder won't raise the error.

The docs here could probably be rewritten to be more helpful. Try submitting a report here.
Was This Post Helpful? 1
  • +
  • -

#3 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Mistake in Python Docs?

Posted 28 August 2011 - 04:36 AM

Then it's fine. I will submit a report. Plus just noted another potential bug: if in using os.rename(), if the src is an absolute path, like C:Users/Kaustav/cool.jpg, and the dst is a just the filename, i.e. newcool.jpg instead of C:Users/Kaustav/newcool.jpg, the file is just lost! No trace of it, whether in C drive, or Python root folder! Bizarre!
Was This Post Helpful? 0
  • +
  • -

#4 Hiram  Icon User is offline

  • D.I.C Head

Reputation: 69
  • View blog
  • Posts: 203
  • Joined: 02-June 09

Re: Mistake in Python Docs?

Posted 28 August 2011 - 08:44 PM

That's a relative move. So it should be moved to the current working directory with the specified name. I'd be very shocked if it completely disappeared.

However I know Windows has some oddities with Python, so of course I can't say definitively whether or not it's a relative move or really disappearing.
Was This Post Helpful? 0
  • +
  • -

#5 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Mistake in Python Docs?

Posted 01 September 2011 - 07:05 AM

View PostHiram, on 29 August 2011 - 03:44 AM, said:

That's a relative move. So it should be moved to the current working directory with the specified name. I'd be very shocked if it completely disappeared.

However I know Windows has some oddities with Python, so of course I can't say definitively whether or not it's a relative move or really disappearing.


No no, like I said, there is no trace of the file, whether in the Python root folder, or anywhere else in the particular drive, or for that matter, anywhere in the entire computer!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1