chatgpt/conver-iso-to-utf8.py

18 lines
493 B
Python
Executable File

#!/usr/bin/python3
import sys
import io
def convert_iso8859_to_utf8(filepath):
# open the file with ISO-8859-1 encoding
with io.open(filepath, 'r', encoding='iso-8859-1') as f:
# read the file's content
content = f.read()
# write the UTF-8 encoded content to a new file
with io.open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
print(f"{filepath} has been converted to UTF-8.")
filepath = sys.argv[1]
convert_iso8859_to_utf8(filepath)