By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,675 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,675 IT Pros & Developers. It's quick & easy.

file copy portability

P: n/a
Is shutil.copyfile(src,dst) the *most* portable way to copy files with
Python? I'm dealing with plain text files on Windows, Linux and Mac OSX.

Thanks!
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Bob Smith wrote:
Is shutil.copyfile(src,dst) the *most* portable way to copy files with
Python? I'm dealing with plain text files on Windows, Linux and Mac OSX.


Yes, provided you don't need any of the features provided by the
other shutil.copy functions, and assuming you can live with the
Caveat listed in the docs for the MacOS system...

-Peter
Jul 18 '05 #2

P: n/a
Bob Smith wrote:
Is shutil.copyfile(src,dst) the *most* portable way to copy files with
Python? I'm dealing with plain text files on Windows, Linux and Mac OSX.

Thanks!


Yes.

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Jul 18 '05 #3

P: n/a

Bob Smith wrote:
Is shutil.copyfile(src,dst) the *most* portable way to copy files with Python? I'm dealing with plain text files on Windows, Linux and Mac OSX.
Thanks!


Portable what? Way of copying??

Do you want your files transferred (a) so that they look like native
text files on the destination system, or (b) so that they are exact
byte-wise copies?

A 5-second squint at the source (Lib/shutil.py) indicates that it
provides, reliably and portably, option b:
fsrc = open(src, 'rb')
fdst = open(dst, 'wb')

One way of doing option (a): you would need to be running Python on the
destination system, open the src file with 'rU', open the dst file with
'w'.

Jul 18 '05 #4

P: n/a
John Machin wrote:
Bob Smith wrote:
Is shutil.copyfile(src,dst) the *most* portable way to copy files


with
Python? I'm dealing with plain text files on Windows, Linux and Mac


OSX.
Thanks!

Portable what? Way of copying??

Do you want your files transferred (a) so that they look like native
text files on the destination system, or (b) so that they are exact
byte-wise copies?

A 5-second squint at the source (Lib/shutil.py) indicates that it
provides, reliably and portably, option b:
fsrc = open(src, 'rb')
fdst = open(dst, 'wb')

One way of doing option (a): you would need to be running Python on the
destination system, open the src file with 'rU', open the dst file with
'w'.


The files are not copied from one platform to the other. The app must
run on all platforms. I want to make the app as portable as possible to
reduce platform specific code.
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.