suppor writing csv and json to stdout; print errors to stderr

- add tests
This commit is contained in:
scito
2022-12-18 19:24:07 +01:00
parent fd1841f8dd
commit 1be4c7e0ef
4 changed files with 138 additions and 28 deletions

View File

@@ -59,7 +59,7 @@ def remove_dir_with_files(dir):
def read_csv(filename):
"""Returns a list of lines."""
with open(filename, "r") as infile:
with open(filename, "r", newline='') as infile:
lines = []
reader = csv.reader(infile)
for line in reader:
@@ -67,12 +67,26 @@ def read_csv(filename):
return lines
def read_csv_str(str):
"""Returns a list of lines."""
lines = []
reader = csv.reader(str.splitlines())
for line in reader:
lines.append(line)
return lines
def read_json(filename):
"""Returns a list or a dictionary."""
with open(filename, "r") as infile:
return json.load(infile)
def read_json_str(str):
"""Returns a list or a dictionary."""
return json.loads(str)
def read_file_to_list(filename):
"""Returns a list of lines."""
with open(filename, "r") as infile: