Last active
January 15, 2020 11:24
-
-
Save bast/ab436984d8ea9db994f145aedbb1a7e8 to your computer and use it in GitHub Desktop.
This file contains 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
import csv | |
import sys | |
import click | |
@click.command() | |
@click.option('--file-name', help='Input file (file is not modified).') | |
@click.option('--index', help='Insert column at this position (starts at 0).') | |
@click.option('--column-name', help='Column name.') | |
def main(file_name, index, column_name): | |
with open(file_name, 'r') as f: | |
reader = csv.reader(f) | |
writer = csv.writer(sys.stdout) | |
for i, row in enumerate(reader): | |
if i == 0: | |
row.insert(int(index), column_name) | |
else: | |
row.insert(int(index), '') | |
writer.writerow(row) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment