Skip to content

Commit 6ad2f8c

Browse files
committed
Write data to CSV file 🐻
1 parent e446b67 commit 6ad2f8c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

postgres/python/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import configparser
2+
import csv
23

34
import psycopg2
45

@@ -23,6 +24,19 @@
2324
results = cursor.fetchall()
2425
print(results)
2526

27+
with open("products.csv", "w") as f:
28+
writer = csv.writer(f)
29+
columns = [(
30+
"UPC",
31+
"DESCRIPTION",
32+
"MANUFACTURER",
33+
"CATEGORY",
34+
"SUB_CATEGORY",
35+
"PRODUCT_SIZE",
36+
)]
37+
writer.writerows(columns)
38+
writer.writerows(results)
39+
2640
query = "SELECT * FROM product;"
2741
cursor = conn.cursor()
2842
cursor.execute(query)

0 commit comments

Comments
 (0)