My end goal is to simplify a text into purely words from one text file to a new one. However it is in french and uses latin chracaters like é, ç or ù. However my code only changes them into a space while it works with ascii characters.
fro example it takes "Messieurs les Présidents," and changes it to "messieurs les pr sidents"
def convert():
for i in files_names:
f1 = open(f"speeches/{i}","r")
L = f1.readlines()
cleaned_text=" "
for j in L:
for k in j :
if ord(k)>=65 and ord(k)<=90: #Changing to lower case
f=chr(ord(k)+32)
cleaned_text+=f
elif (ord(k)>=97 and ord(k)<=122): #keeping lower case letters
cleaned_text+=k
elif (ord(k)>=224 and ord(k)<=254): #keeping lower case latins
cleaned_text+=k
print(k)
else:
if cleaned_text[-1]!=" ":
cleaned_text+=" "
f1.close()
f2 = open(f"./cleaned/{i}","w")
for i in cleaned_text[1:]:
f2.write(i)
f2.close()
this is what my code looks like, I added a seperate if statement to print any entries in the latin case but there are none.
In the end the problem wasn't with python since it is based in UTF-8. It was with the os import that doesn't open files in UTF-8 automatically and had to be told. Here's the fixed and cleaned up code for anyone who's looking to have a little fun.