RosettaCodeData/Task/Read-a-file-character-by-character-UTF8/Python/read-a-file-character-by-character-utf8-2.py
2023-07-01 13:44:08 -04:00

11 lines
276 B
Python

def get_next_character(f):
"""Reads one character from the given textfile"""
c = f.read(1)
while c:
yield c
c = f.read(1)
# Usage:
with open("input.txt", encoding="utf-8") as f:
for c in get_next_character(f):
print(c, sep="", end="")