On 24 February 2018 at 17:17, Peng Yu <pengyu...@gmail.com> wrote:
> Here shows some code for reading Unicode characters one by one in
> python2. Is it the best code for reading Unicode characters one by one
> in python2?
>
> https://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8#Python

No, it’s terrible. So is the Python 3 version. All you need for both
Pythons is this:

import io
with io.open('input.txt', 'r', encoding='utf-8') as fh:
    for character in fh:
        print(character)

(and please make sure you need to read character-by-character first)

-- 
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to