Copy a file in python
Mikael Olofsson
mikael at isy.liu.se
Wed Dec 4 04:32:54 EST 2002
On 4 Dec 2002 00:46:29 -0800
anandpillai6 at yahoo.com (Anand) wrote:
> What is the function to copy a file in python?
If I were to be verbose, I would probably do the following
originalFile = open(originalPath,'r')
targetFile = open(targetPath,'w')
targetFile.write(originalfile.read())
But to be honest, I would rather write this as
open(targetPath,'w').write(open(originalPath,'r').read())
Note: For huge files, there are other ways that are better.
HTH
/Mikael
-----------------------------------------------------------------------
E-Mail: mikael at isy.liu.se
WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone: +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
/"\
\ / ASCII Ribbon Campaign
X Against HTML Mail
/ \
This message was sent by Sylpheed.
-----------------------------------------------------------------------
Linköpings kammarkör: www.kammarkoren.com
More information about the Python-list
mailing list