How to copy a binary file?

Samuel A. Falvo II kc5tja at armored.net
Wed Jan 19 23:12:50 EST 2000


> def file_copy(source, dest):
>     in_file = open(source, 'r')
>     out_file = open(dest, 'w')

Try:

  in_file = open( source, 'rb' )
  out_file = open( dest, 'wb' )

This way, you're always opening the file in _binary_ mode instead of the
default, text mode.  I suspect that your reads are stopping at end-of-line
characters.






More information about the Python-list mailing list