Spaces:
Runtime error
Runtime error
Create livecsv.py
Browse files- livecsv.py +32 -0
livecsv.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
x_value = 0
|
| 6 |
+
total_1 = 1000
|
| 7 |
+
total_2 = 1000
|
| 8 |
+
|
| 9 |
+
fieldnames = ["x_value", "total_1", "total_2"]
|
| 10 |
+
|
| 11 |
+
with open('data.csv', 'w') as csv_file:
|
| 12 |
+
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
|
| 13 |
+
csv_writer.writeheader()
|
| 14 |
+
|
| 15 |
+
while True:
|
| 16 |
+
with open('data.csv', 'a') as csv_file:
|
| 17 |
+
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
|
| 18 |
+
|
| 19 |
+
info = {
|
| 20 |
+
"x_value": x_value,
|
| 21 |
+
"total_1": total_1,
|
| 22 |
+
"total_2": total_2
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
csv_writer.writerow(info)
|
| 26 |
+
print(x_value, total_1, total_2)
|
| 27 |
+
|
| 28 |
+
x_value += 1
|
| 29 |
+
total_1 = total_1 + random.randint(-5, 6)
|
| 30 |
+
total_2 = total_2 + random.randint(-5, 6)
|
| 31 |
+
|
| 32 |
+
time.sleep(1)
|