I have a file(input.txt
) with below content:
é
and I am running the below commands and failing to replace unicode character with character "a"
Attempt 1: Prints blank.
>>> file = open("input.txt","r")
>>> print file.read().replace(u"\u00E9","a")
Attempt 2: Prints blank.
>>> file = open("input.txt","r")
>>> print file.read().decode("utf-8").replace(u"\u00E9","a").encode("utf-8")
Note: I have gone through this question and the answer(Attempt 2) suggested there is not working, not sure why.
EDIT:
As pointed in the comments by ShadowRanger, My question was incomplete. My apologies for that.
Here is the complete code for Attempt 1:
>>> file = open("input.txt","r")
>>> print file.read()
>>> é
>>> print file.read().replace(u"\u00E9","a")
>>>
Here is the complete code for Attempt 2:
>>> file = open("input.txt","r")
>>> print file.read()
>>> é
>>> print file.read().decode("utf-8").replace(u"\u00E9","a").encode("utf-8")
>>>