From a252ae01a051792565d8b39b74ad3c03215e8830 Mon Sep 17 00:00:00 2001 From: RickyChan Date: Fri, 5 Jun 2020 19:00:52 +0800 Subject: [PATCH] Fix csv DictWriter parameter --- bin/import_cv.py | 2 +- bin/import_lingua_libre.py | 6 +++--- bin/import_m-ailabs.py | 6 +++--- bin/import_slr57.py | 6 +++--- bin/import_swc.py | 2 +- bin/import_ts.py | 6 +++--- bin/import_tuda.py | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bin/import_cv.py b/bin/import_cv.py index e4251c1a..3754694f 100755 --- a/bin/import_cv.py +++ b/bin/import_cv.py @@ -127,7 +127,7 @@ def _maybe_convert_set(extracted_dir, source_csv, target_csv): pool.join() print('Writing "%s"...' % target_csv) - with open(target_csv, "w") as target_csv_file: + with open(target_csv, "w", encoding="utf-8", newline="") as target_csv_file: writer = csv.DictWriter(target_csv_file, fieldnames=FIELDNAMES) writer.writeheader() bar = progressbar.ProgressBar(max_value=len(rows), widgets=SIMPLE_BAR) diff --git a/bin/import_lingua_libre.py b/bin/import_lingua_libre.py index 6992d298..ec5047ba 100755 --- a/bin/import_lingua_libre.py +++ b/bin/import_lingua_libre.py @@ -136,9 +136,9 @@ def _maybe_convert_sets(target_dir, extracted_data): pool.close() pool.join() - with open(target_csv_template.format("train"), "w") as train_csv_file: # 80% - with open(target_csv_template.format("dev"), "w") as dev_csv_file: # 10% - with open(target_csv_template.format("test"), "w") as test_csv_file: # 10% + with open(target_csv_template.format("train"), "w", encoding="utf-8", newline="") as train_csv_file: # 80% + with open(target_csv_template.format("dev"), "w", encoding="utf-8", newline="") as dev_csv_file: # 10% + with open(target_csv_template.format("test"), "w", encoding="utf-8", newline="") as test_csv_file: # 10% train_writer = csv.DictWriter(train_csv_file, fieldnames=FIELDNAMES) train_writer.writeheader() dev_writer = csv.DictWriter(dev_csv_file, fieldnames=FIELDNAMES) diff --git a/bin/import_m-ailabs.py b/bin/import_m-ailabs.py index e303feb3..963b2873 100755 --- a/bin/import_m-ailabs.py +++ b/bin/import_m-ailabs.py @@ -137,9 +137,9 @@ def _maybe_convert_sets(target_dir, extracted_data): pool.close() pool.join() - with open(target_csv_template.format("train"), "w") as train_csv_file: # 80% - with open(target_csv_template.format("dev"), "w") as dev_csv_file: # 10% - with open(target_csv_template.format("test"), "w") as test_csv_file: # 10% + with open(target_csv_template.format("train"), "w", encoding="utf-8", newline="") as train_csv_file: # 80% + with open(target_csv_template.format("dev"), "w", encoding="utf-8", newline="") as dev_csv_file: # 10% + with open(target_csv_template.format("test"), "w", encoding="utf-8", newline="") as test_csv_file: # 10% train_writer = csv.DictWriter(train_csv_file, fieldnames=FIELDNAMES) train_writer.writeheader() dev_writer = csv.DictWriter(dev_csv_file, fieldnames=FIELDNAMES) diff --git a/bin/import_slr57.py b/bin/import_slr57.py index 1aa0e4d2..11e30fa4 100755 --- a/bin/import_slr57.py +++ b/bin/import_slr57.py @@ -159,9 +159,9 @@ def _maybe_convert_sets(target_dir, extracted_data): pool.close() pool.join() - with open(target_csv_template.format("train"), "w") as train_csv_file: # 80% - with open(target_csv_template.format("dev"), "w") as dev_csv_file: # 10% - with open(target_csv_template.format("test"), "w") as test_csv_file: # 10% + with open(target_csv_template.format("train"), "w", encoding="utf-8", newline="") as train_csv_file: # 80% + with open(target_csv_template.format("dev"), "w", encoding="utf-8", newline="") as dev_csv_file: # 10% + with open(target_csv_template.format("test"), "w", encoding="utf-8", newline="") as test_csv_file: # 10% train_writer = csv.DictWriter(train_csv_file, fieldnames=FIELDNAMES) train_writer.writeheader() dev_writer = csv.DictWriter(dev_csv_file, fieldnames=FIELDNAMES) diff --git a/bin/import_swc.py b/bin/import_swc.py index d19f7c3e..0c0ceb64 100755 --- a/bin/import_swc.py +++ b/bin/import_swc.py @@ -461,7 +461,7 @@ def write_csvs(samples, language): base_dir = os.path.abspath(CLI_ARGS.base_dir) csv_path = os.path.join(base_dir, language + "-" + sub_set + ".csv") print('Writing "{}"...'.format(csv_path)) - with open(csv_path, "w") as csv_file: + with open(csv_path, "w", encoding="utf-8", newline="") as csv_file: writer = csv.DictWriter( csv_file, fieldnames=FIELDNAMES_EXT if CLI_ARGS.add_meta else FIELDNAMES ) diff --git a/bin/import_ts.py b/bin/import_ts.py index 86f5eab7..e6cdc1e8 100755 --- a/bin/import_ts.py +++ b/bin/import_ts.py @@ -131,9 +131,9 @@ def _maybe_convert_sets(target_dir, extracted_data, english_compatible=False): pool.close() pool.join() - with open(target_csv_template.format("train"), "w") as train_csv_file: # 80% - with open(target_csv_template.format("dev"), "w") as dev_csv_file: # 10% - with open(target_csv_template.format("test"), "w") as test_csv_file: # 10% + with open(target_csv_template.format("train"), "w", encoding="utf-8", newline="") as train_csv_file: # 80% + with open(target_csv_template.format("dev"), "w", encoding="utf-8", newline="") as dev_csv_file: # 10% + with open(target_csv_template.format("test"), "w", encoding="utf-8", newline="") as test_csv_file: # 10% train_writer = csv.DictWriter(train_csv_file, fieldnames=FIELDNAMES) train_writer.writeheader() dev_writer = csv.DictWriter(dev_csv_file, fieldnames=FIELDNAMES) diff --git a/bin/import_tuda.py b/bin/import_tuda.py index fa48de61..5facd073 100755 --- a/bin/import_tuda.py +++ b/bin/import_tuda.py @@ -111,7 +111,7 @@ def write_csvs(extracted): CLI_ARGS.base_dir, "tuda-{}-{}.csv".format(TUDA_VERSION, sub_set) ) print('Writing "{}"...'.format(csv_path)) - with open(csv_path, "w") as csv_file: + with open(csv_path, "w", encoding="utf-8", newline="") as csv_file: writer = csv.DictWriter(csv_file, fieldnames=FIELDNAMES) writer.writeheader() set_dir = os.path.join(extracted, sub_set)