Skip to content

Commit 625fc5c

Browse files
authored
Update main.py
1 parent 6bccee3 commit 625fc5c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

better-python/main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def read_large_csv_with_generator(file_path: str) -> Generator[Dict[str, str], N
3131
print(row)
3232

3333
# Caching
34-
3534
from functools import cache
3635
from typing import Tuple
3736
import numpy as np
@@ -46,3 +45,13 @@ def assign_clusters(data: np.ndarray, centroids: np.ndarray) -> np.ndarray:
4645
distances = [euclidean_distance(tuple(point), tuple(centroid)) for centroid in centroids]
4746
clusters[i] = np.argmin(distances)
4847
return clusters
48+
49+
# Context managers
50+
import sqlite3
51+
52+
def query_db(db_path):
53+
with sqlite3.connect(db_path) as conn:
54+
cursor = conn.cursor()
55+
cursor.execute(query)
56+
for row in cursor.fetchall():
57+
yield row

0 commit comments

Comments
 (0)