From 42920e9c7c52b4aaa2b25cc774cf0fb2ab0ce26a Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Mon, 29 Jul 2019 16:16:30 +0300 Subject: [PATCH] Test Python regular expression matches directly Match objects always have a boolean value of True. See: https://docs.python.org/3.7/library/re.html --- csv_metadata_quality/check.py | 2 +- csv_metadata_quality/fix.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/csv_metadata_quality/check.py b/csv_metadata_quality/check.py index 82e771e..28640cd 100755 --- a/csv_metadata_quality/check.py +++ b/csv_metadata_quality/check.py @@ -69,7 +69,7 @@ def separators(field): # After splitting, see if there are any remaining "|" characters match = re.findall(r'^.*?\|.*$', value) - if len(match) > 0: + if match: print(f'Invalid multi-value separator: {field}') return field diff --git a/csv_metadata_quality/fix.py b/csv_metadata_quality/fix.py index 0bec8e2..1d273ef 100755 --- a/csv_metadata_quality/fix.py +++ b/csv_metadata_quality/fix.py @@ -24,8 +24,8 @@ def whitespace(field): pattern = re.compile(r'\s{2,}') match = re.findall(pattern, value) - if len(match) > 0: print(f'Excessive whitespace: {value}') + if match: value = re.sub(pattern, ' ', value) # Save cleaned value @@ -53,7 +53,7 @@ def separators(field): pattern = re.compile(r'\|') match = re.findall(pattern, value) - if len(match) > 0: + if match: print(f'Fixing invalid multi-value separator: {value}') value = re.sub(pattern, '||', value)