[Tutor] os.rename vs. shutil.move

Bill Allen wallenpb at gmail.com
Sun Apr 17 01:56:50 CEST 2011


Ok, thanks.

--Bill



On Sat, Apr 16, 2011 at 18:15, Steven D'Aprano <steve at pearwood.info> wrote:

> Bill Allen wrote:
>
>> What are the particular advantages or disadvantages concerning using
>> either
>> os.rename or shutil.move to rename a file.   I have tried both and for
>> simple renaming they seem equivalent.
>>
>
> Consider non-simple renaming.
>
> At the interactive interpreter, call:
>
> help(os.rename)
>
> and then
>
> help(shutil.move)
>
> to be enlightened.
>
> And read the Fine Manual:
>
> http://docs.python.org/library/shutil.html
>
> which conveniently now links directly to the source code, so you can see
> for yourself all the extra work shutil.move does to cover cases which
> os.rename may not cover (depending on the OS and/or file system).
>
> http://docs.python.org/library/os.html#os.rename
>
> os.rename is a thin wrapper around your file system's rename/mv command,
> with the same limitations as it has. shutil.move attempts to do extra work
> to overcome such limitations.
>
>
>
> --
> Steven
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110416/fc4cdeec/attachment.html>


More information about the Tutor mailing list