I want to replace the character ي (Unicode:\u064A) With the character ی (Unicode:\u06CC). I tried the following code:
import unicodedata as ud
normalForm = ud.normalize('NFKD','رزاﻗﻲ')
for charr in normalForm:
if charr == 'ي':
print('true')
charr = charr.replace('ي','ی')
print(normalForm)
However, this code doesn't work, and it returns the same character:
رزاقي
while it should return:
رزاقی
I wanted to try replacing using their Unicode (or any other method), How can I achieve this?
normalForm = normalForm.replace(…). You need to call replace on the whole string and reassign it, not just a single character.charr = charr.replace('ي','ی')doesn't impact the original string, becausecharris a separate string object that exists independently of thenormalForm. That said,.replaceis designed to operate on entire strings already. Remember, Python doesn't have a separate type for individual characters. It just makes separate length-1 strings.