Last active
February 1, 2019 12:57
-
-
Save spookyahell/0867037d412ec4ca4efcb0e13785afc3 to your computer and use it in GitHub Desktop.
Convert a filename with spaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from copy import copy | |
def convertToDotted(stri): | |
output = '' | |
previous_char = None | |
for char in stri: | |
x = re.fullmatch(r'\w', char) | |
umlaut_repl = {'ö':'oe','ü':'ue','ä':'ae','ß':'ss'} | |
if char in umlaut_repl.keys(): | |
output += umlaut_repl[char] | |
elif x: | |
output += char | |
elif char == ' ': | |
if previous_char != ' ': | |
output += '.' | |
elif char in ['.','-']: | |
output += char | |
previous_char = copy(char) | |
return output | |
if __name__ == '__main__': | |
print(convertToDotted('Some file with spaces convörts - to some file without spaces!')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment