[ACCEPTED]-Reading utf-8 escape sequences from a file-utf8-decode

Accepted answer
Score: 10

According to this answer, changing the following should 1 have the expected result.

In Python 3:

codecs.open(file, 'r', encoding='utf-8') to

codecs.open(file, 'r', encoding='unicode_escape')

In Python 2:

codecs.open(file, 'r', encoding='string_escape')

Score: 1

If you want to output text to console with 7 the same formatting, then the point is, that 6 UNIX (or what OS do you use?) uses ANSI 5 escape sequences different from those in 4 IRC, so you have to translate IRC format 3 to UNIX format. these are the links to start:
Color text in terminal applications in UNIX

If 2 you want to print text without formating, just 1 clean it, by using regexp.

Score: 1

The solution, as some people suggested is 5 using codecs.open(file, 'r', encoding='unicode_escape'), which will look like the following 4 once implemented:

with codecs.open(file, 'r', encoding='unicode_escape') as q:
    quotes = q.readlines()


If you use regular utf-8 3 decoding, the result for \x02I don't like \x0307bananas\x03.\x02 will actually 2 be "\\x02I don't like \\x0307bananas\\x03.\\x02\n" because readlines() method will escape the characters 1 for you

More Related questions