Skip to content

Commit dd1c2d7

Browse files
committed
Specify explicit encoding for Windows
1 parent 5c998dc commit dd1c2d7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

binary-search/download_imdb.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def main():
1919

2020
print("Fetching data from IMDb...")
2121

22-
with open("names.txt", "w") as destination:
22+
with open("names.txt", "w", encoding="utf-8") as destination:
2323
destination.writelines(names())
2424

25-
with open("names.txt") as source, open(
26-
"sorted_names.txt", "w"
25+
with open("names.txt", encoding="utf-8") as source, open(
26+
"sorted_names.txt", "w", encoding="utf-8"
2727
) as destination:
2828
destination.writelines(sorted(source.readlines()))
2929

@@ -37,12 +37,12 @@ def names():
3737
with tempfile.NamedTemporaryFile(mode="w+b") as archive:
3838
shutil.copyfileobj(response, archive)
3939
archive.seek(0)
40-
with gzip.open(archive, mode="rt") as tsv_file:
41-
tsv = csv.reader(tsv_file, delimiter='\t')
40+
with gzip.open(archive, mode="rt", encoding="utf-8") as tsv_file:
41+
tsv = csv.reader(tsv_file, delimiter="\t")
4242
next(tsv) # Skip the header
4343
for record in tsv:
4444
full_name = record[1]
45-
yield f'{full_name}\n'
45+
yield f"{full_name}\n"
4646

4747

4848
if __name__ == "__main__":

0 commit comments

Comments
 (0)