Created
February 19, 2016 10:08
-
-
Save icedraco/42eed096b1349e21fd25 to your computer and use it in GitHub Desktop.
A piece of code that copies the first line from file A into file B. Used to copy CSV headerss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # We take CSV headers from this file... | |
| src_file = "source.csv" | |
| # ...and add to this file as the first line | |
| dst_file = "destination.csv" | |
| # Output file that's created (to avoid possibly damaging the destination file) | |
| output_file = "output.csv" | |
| # Read the first line from source and add to output | |
| headers = open(src_file, 'r').readline() | |
| fd = open(output_file, 'w') | |
| fd.write(headers) | |
| # Copy destination file into output line-by-line (to avoid reading large files into RAM) | |
| for line in open(dst_file, 'r'): | |
| fd.write(line) | |
| fd.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment