Skip to content

Instantly share code, notes, and snippets.

@spookyahell
Last active February 1, 2019 12:57
Show Gist options
  • Save spookyahell/0867037d412ec4ca4efcb0e13785afc3 to your computer and use it in GitHub Desktop.
Save spookyahell/0867037d412ec4ca4efcb0e13785afc3 to your computer and use it in GitHub Desktop.
Convert a filename with spaces
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