Fix csv newline handling in movie-lister example

This commit is contained in:
ZipFile 2025-06-01 17:35:32 +00:00
parent a322584308
commit 51c7db771d
2 changed files with 3 additions and 4 deletions

View File

@ -18,10 +18,9 @@ SQLITE_FILE = DIR / "movies.db"
def create_csv(movies_data, path):
with open(path, "w") as opened_file:
with open(path, "w", newline="") as opened_file:
writer = csv.writer(opened_file)
for row in movies_data:
writer.writerow(row)
writer.writerows(movies_data)
def create_sqlite(movies_data, path):

View File

@ -29,7 +29,7 @@ class CsvMovieFinder(MovieFinder):
super().__init__(movie_factory)
def find_all(self) -> List[Movie]:
with open(self._csv_file_path) as csv_file:
with open(self._csv_file_path, newline="") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=self._delimiter)
return [self._movie_factory(*row) for row in csv_reader]