Last active
December 12, 2015 05:28
-
-
Save informationsea/4721768 to your computer and use it in GitHub Desktop.
Convert CSV to Tab separated Text
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
#!/usr/bin/env python | |
__author__ = "OKAMURA Yasunobu" | |
__license__ = "GPL3+" | |
import argparse | |
import csv | |
import sys | |
def _main(): | |
parser = argparse.ArgumentParser(description="Convert CSV to Tab separated") | |
parser.add_argument('input', default=sys.stdin, type=argparse.FileType('r'), nargs='?') | |
parser.add_argument('output', default=sys.stdout, type=argparse.FileType('w'), nargs='?') | |
parser.add_argument('--input-delimiter', default=',', help='[default: %(default)s]') | |
parser.add_argument('--input-quote', default='"', help='[default: %(default)s]') | |
parser.add_argument('--output-delimiter', default='\t', help='[default: %(default)s]') | |
parser.add_argument('--output-quote', default=None, help='[default: %(default)s]') | |
options = parser.parse_args() | |
reader = csv.reader(options.input, delimiter=options.input_delimiter, quotechar=options.input_quote) | |
writer = csv.writer(options.output, delimiter=options.output_delimiter, quotechar=options.output_quote) | |
for line in reader: | |
writer.writerow(line) | |
if __name__ == '__main__': | |
_main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment