From 7bd02f37db08c0f0f52d7a21978338aa1f182564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Tue, 19 Sep 2017 16:05:13 +0200 Subject: [PATCH] Improve whitespace elimination with re.sub() --- normalisename.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/normalisename.py b/normalisename.py index da4d163..7fed33e 100755 --- a/normalisename.py +++ b/normalisename.py @@ -3,6 +3,7 @@ from unidecode import unidecode from os import rename from os.path import basename, dirname from os.path import join as joinpath +from re import sub as substitute from argparse import ArgumentParser from sys import exit @@ -45,7 +46,7 @@ class normalisename: return file == self.normalname(file) def normalname(self, filename): - return unidecode(''.join(ch for ch in filename.replace(' ', self.separator) + return unidecode(''.join(ch for ch in substitute('\s+', self.separator, filename) if ch.isalnum() or ch in self.whitelist))