Skip to content

Commit c7d19ab

Browse files
committed
add logic to read and write in temp file
1 parent b25cac6 commit c7d19ab

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

python_csv/editing_csv_data.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,21 @@
22
import shutil
33

44
from tempfile import NamedTemporaryFile
5+
6+
FILE_NAME = 'data.csv'
7+
temp_file = NamedTemporaryFile(delete=False)
8+
9+
with open(FILE_NAME, 'wb', , newline='') as csvfile, temp_file:
10+
reader = csv.DictReader(csvfile)
11+
fieldnames = ['id', 'name', 'email', 'amount', '']
12+
writer = csv.DictWriter(temp_file, fieldnames=fieldnames)
13+
writer.writeheader()
14+
15+
for row in reader:
16+
writer.writerow({
17+
"id": row["id"],
18+
"name": row["name"],
19+
"email": row["email"],
20+
"amount": "599.99",
21+
"sent": ""
22+
})

0 commit comments

Comments
 (0)