2022-05-28 16:27:40 +02:00
|
|
|
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)
|
2022-05-28 17:05:22 +02:00
|
|
|
for row in output: writer.writerow([row])
|