Advertisement
steve-shambles-2109

199-Merge files

Nov 9th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. """
  2. Python code snippets vol 40.
  3. 199-Merge files.
  4. stevepython.wordpress.com
  5.  
  6. based on, source:
  7. https://codescracker.com/python/program/python-program-merge-two-files.htm
  8. """
  9.  
  10. import shutil
  11. import webbrowser
  12.  
  13. first_file = 'test.txt'
  14. second_file = 'test2.txt'
  15. merged_file = 'merged.txt'
  16.  
  17. with open(merged_file, 'wb') as wfd:
  18.     for f in [first_file, second_file]:
  19.         with open(f, 'rb') as fd:
  20.             shutil.copyfileobj(fd, wfd, 1024*1024*10)
  21.  
  22. webbrowser.open(merged_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement