-1

I have a problem, and it is that I have a sentence that contains this:

Debes modificar la dieta que est \xc3\xa1 s consumiendo, para que te sientas con m \xc3\xa1 s energ \xc3\xad a y vitalidad, mejorando tu calidad de vida de una forma extraordinaria. Si no sabes por donde empezar, busca ayuda en un nutricionista que te guie en este cambio tan beneficioso para tu organismo.

and I want to transform

  • \xc3\xa1 -> á
  • \xc3\xad -> í

I tried to replace in python but it doesn't work.

What should I do?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • 2
    I'm confused. That can't be a string, because `'\xc3\xa1'` becomes `'á'`. Please post the data itself. See [mre] for reference. BTW welcome to SO! Check out the [tour]. – wjandrea Dec 22 '20 at 16:02
  • We need more information, particularly stuff like what data type you have and whether it contains literal unparsed escape sequences or characters/bytes that show up escaped in the `repr` output. Can you post `repr(whatever_this_object_is)`? – user2357112 Dec 22 '20 at 16:17
  • [Screenshot](https://prnt.sc/w8bm6o) – a guy woth problemas Dec 23 '20 at 07:49

1 Answers1

0

This works...

b'\xc3\xa1'.decode("utf-8")
b'\xc3\xad'.decode("utf-8")

enter image description here

To add this into your script you can add these lines into your script after your replace commands.

salud_list = salud.split(' ')

for word in salud_list:
    if isinstance(word,bytes):
        word = word.decode("utf-8")

print(' '.join(salud_list))
Dunski
  • 653
  • 5
  • 14