Minute(n) Lesezeit
Ich habe vor einiger Zeit schon dieses Python Script geschrieben, um die Umlaute einer Textdatei umzuwandeln.Ich habe die Datei unter umlaute_converter.py gespeichert.
import sys def umlaute_to_ascii(text): # Umlaute ersetzen text = text.replace('ä', 'ae') text = text.replace('ö', 'oe') text = text.replace('ü', 'ue') text = text.replace('ß', 'ss') text = text.replace('Ä', 'Ae') text = text.replace('Ö', 'Oe') text = text.replace('Ü', 'Ue') return text # Überprüfen, ob die richtige Anzahl von Argumenten übergeben wurde if len(sys.argv) != 3: print("Verwendung: python umlaute_converter.py input.txt output.txt") else: input_file = sys.argv[1] output_file = sys.argv[2] try: # Eingabetext aus der Datei lesen with open(input_file, 'r', encoding='utf-8') as file: input_text = file.read() # Umlaute in ASCII umwandeln output_text = umlaute_to_ascii(input_text) # Ergebnis in Ausgabedatei schreiben with open(output_file, 'w', encoding='utf-8') as file: file.write(output_text) print(f"Umlaute wurden erfolgreich aus '{input_file}' in '{output_file}' umgewandelt.") except FileNotFoundError: print("Die angegebene Eingabedatei wurde nicht gefunden.")