0

I have a file that has random unicode characters in it and I would like to un-escape them. For example, \uE0001 would become uE0001 and \uFEFF would become uFEFF. So far, I have:

with open(path, encoding="utf-8") as f:
    s = f.read()
    s = s.replace("\\u", "u")
with open(fpath, "w"):
    f.write(s)

But that gives the error:

UnicodeEncodeError: 'charmap' codec can't encode character '\ufeff' in position 0: character maps to <undefined>

Either I did something wrong when replacing so there are still unicode characters, or python is still trying to encode it. What did I do wrong here, and how can I get a working program?

Beckett O'Brien
  • 176
  • 2
  • 16

0 Answers0