How to convert default string character to original one in Python 3.x?

Viewed 54

I want to correct the file name which is written different from original language in Python 3.x.

File name is HIB_GUNLUK_GERÇEK_EVAPOTRANSPIRASYONLAR_MM_BOLU_GUN.csv

But I want to see that as HIB_GUNLUK_GERÇEK_EVAPOTRANSPIRASYONLAR_MM_BOLU_GUN.csv.

Briefly my file name consists Ç instead of Ç. How can I fix that. Because I use for loop to see the files and file names are controlled with if statement. If I compare this it returns False:

>>HIB_GUNLUK_GERÇEK_EVAPOTRANSPIRASYONLAR_MM_BOLU_GUN.csv == HIB_GUNLUK_GERÇEK_EVAPOTRANSPIRASYONLAR_MM_BOLU_GUN.csv
False
1 Answers

Encode from the incorrect Windows-1252 to get the original bytes back, then decode as the UTF-8 that it actually was:

>>> 'HIB_GUNLUK_GERÇEK_EVAPOTRANSPIRASYONLAR_MM_BOLU_GUN.csv'.encode('cp1252').decode('utf-8')
'HIB_GUNLUK_GERÇEK_EVAPOTRANSPIRASYONLAR_MM_BOLU_GUN.csv'
Related