Skip to content

Commit 5c998dc

Browse files
committed
Use a built-in CSV module
1 parent fd0ddc0 commit 5c998dc

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

binary-search/download_imdb.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
$ python download_imdb.py
88
"""
99

10+
import csv
1011
import gzip
1112
import shutil
1213
import tempfile
@@ -36,11 +37,12 @@ def names():
3637
with tempfile.NamedTemporaryFile(mode="w+b") as archive:
3738
shutil.copyfileobj(response, archive)
3839
archive.seek(0)
39-
with gzip.open(archive, mode="rt") as source:
40-
next(source) # Skip the header
41-
for line in source:
42-
full_name = line.split("\t")[1]
43-
yield f"{full_name}\n"
40+
with gzip.open(archive, mode="rt") as tsv_file:
41+
tsv = csv.reader(tsv_file, delimiter='\t')
42+
next(tsv) # Skip the header
43+
for record in tsv:
44+
full_name = record[1]
45+
yield f'{full_name}\n'
4446

4547

4648
if __name__ == "__main__":

0 commit comments

Comments
 (0)