python-2.7nao-robotchoregraphe

How to encode text in Choregraphe NAO


Encoded text I want to read list from file but its getting all coded and .encode doesn't really work

    import json,sys
    with open('your_file.txt') as f:
        lines = f.read().splitlines()

    self.logger.info(lines)
    self.tts.say(lines[1])

Solution

  • If your file is saved with UTF-8 encoding, this should work:

    with open('text.txt', encoding = 'utf-8', mode = 'r') as my_file: 
    

    If this doesn't work, your text file's encoding is not UTF-8. Write your file's encoding in place of utf-8. How to determine the encoding of text?

    Or if you share your input file as is, I can figure that out for you.