-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfix.py
More file actions
19 lines (15 loc) · 683 Bytes
/
fix.py
File metadata and controls
19 lines (15 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Programm zur Behebung des UTF-8-Encoding-Problems
def fix_encoding(file_path):
# Öffnen der Datei zum Lesen
with open(file_path, 'r', encoding='latin1') as file:
lines = file.readlines()
# Überprüfen, ob die Encoding-Zeile bereits vorhanden ist
if not lines[0].startswith("# -*- coding: utf-8 -*-"):
# UTF-8-Encoding-Zeile hinzufügen
lines.insert(0, "# -*- coding: utf-8 -*-\n")
# Schreiben der geänderten Datei
with open(file_path, 'w', encoding='utf-8') as file:
file.writelines(lines)
# Beispiel für die Verwendung
file_path ='serve+.py' #"musicanno.py" # # Pfad zur Datei
fix_encoding(file_path)