1
0
mirror of https://github.com/ilri/csv-metadata-quality.git synced 2024-11-25 15:18:19 +01:00

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
This commit is contained in:
Alan Orth 2019-07-29 16:16:30 +03:00
parent 7b5db1f5d9
commit 42920e9c7c
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
2 changed files with 3 additions and 3 deletions

View File

@ -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

View File

@ -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)