25 lines
796 B
Python
25 lines
796 B
Python
import csv, lzma
|
|
|
|
# Reads input from directory and returns a list
|
|
def read(dir):
|
|
X = []
|
|
if 'xz' in dir:
|
|
with lzma.open(dir) as f:
|
|
for line in f:
|
|
text = line.decode('utf-8')
|
|
text = text.replace('\n', '').split('\t')
|
|
X.append(text)
|
|
else:
|
|
with open(dir, encoding='utf-8') as f:
|
|
for line in f:
|
|
if 'tsv' in dir:
|
|
X.append(line.replace('\n', '').split('\t'))
|
|
else:
|
|
X.append(line.replace('\n', ''))
|
|
return X
|
|
|
|
# Takes the output (list) and writes it into directory
|
|
def write(output, dir):
|
|
with open(dir, 'w', newline='', encoding='utf-8') as f:
|
|
writer = csv.writer(f)
|
|
for row in output: writer.writerow([row]) |