Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,20 @@
|
|||
def get_next_character(f):
|
||||
# note: assumes valid utf-8
|
||||
c = f.read(1)
|
||||
while c:
|
||||
while True:
|
||||
try:
|
||||
yield c.decode('utf-8')
|
||||
except UnicodeDecodeError:
|
||||
# we've encountered a multibyte character
|
||||
# read another byte and try again
|
||||
c += f.read(1)
|
||||
else:
|
||||
# c was a valid char, and was yielded, continue
|
||||
c = f.read(1)
|
||||
break
|
||||
|
||||
# Usage:
|
||||
with open("input.txt","rb") as f:
|
||||
for c in get_next_character(f):
|
||||
print(c)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
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="")
|
||||
Loading…
Add table
Add a link
Reference in a new issue