Improve whitespace elimination with re.sub()

This commit is contained in:
Kjistóf 2017-09-19 16:05:13 +02:00 committed by Kristóf Tóth
parent 24cd974129
commit 7bd02f37db

View File

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