file copy portability

John Machin sjmachin at lexicon.net
Tue Jan 18 20:11:34 EST 2005


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'.




More information about the Python-list mailing list