Skip to content

Commit 9895aff

Browse files
committed
ex 6.5
1 parent 88a946b commit 9895aff

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Work/follow.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# follow.py
2+
import os
3+
import time
4+
5+
f = open("Data/stocklog.csv")
6+
f.seek(0, os.SEEK_END) # Move file pointer 0 bytes from end of file
7+
8+
while True:
9+
line = f.readline()
10+
if line == "":
11+
time.sleep(0.1) # Sleep briefly and retry
12+
continue
13+
fields = line.split(",")
14+
name = fields[0].strip('"')
15+
price = float(fields[1])
16+
change = float(fields[4])
17+
if change < 0:
18+
print(f"{name:>10s} {price:>10.2f} {change:>10.2f}")

0 commit comments

Comments
 (0)