Created
November 8, 2018 07:37
-
-
Save harukaeru/97c009c5903d66ca92bf162a532482b1 to your computer and use it in GitHub Desktop.
Create a table from linear texts which contain columns and rows
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 argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("filename", help="You set here files to parse.") | |
parser.add_argument( | |
"--transpose", | |
default=False, action='store_true', | |
help="Exchange column header and row header." | |
) | |
args = parser.parse_args() | |
lines = open(args.filename).readlines() | |
removed_lb_lines = [line.replace('\n', '') for line in lines] | |
x = [] | |
y = [] | |
is_switched = False | |
for line in removed_lb_lines: | |
if line == '---': | |
is_switched = True | |
continue | |
if args.transpose ^ is_switched: | |
y.append(line) | |
else: | |
x.append(line) | |
out = '' | |
out += '\t' + '\t'.join(x) + '\n' | |
for y_el in y: | |
out += y_el + '\n' | |
print(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment