Copying contents of one file to a different file

Download python eBook

Example

with open(input_file, 'r') as in_file, open(output_file, 'w') as out_file:
    for line in in_file:
        out_file.write(line)
  • Using the shutil module:
import shutil
shutil.copyfile(src, dst)

Stats

Contributors: 2
2016-04-15
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook