0

I have a similar problem to the one described here below in a different question: Reading from a CSV file while it is being written to

Unfortunately the solution is not explained.

I'd like to create a script that plots some variables in a .csv file dynamically. The .csv is updated everytime a sensor registers something. My basic idea was to read the file each fixed period of time and if the number of rows is increased, to update the plot with the new variables.

How can I proceed?

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
Fabrizio
  • 1
  • 2
  • The solution in your linked question says you can do `tailf csv_file | python your_script.py` and then read from `stdin`. Why doesn't that work for you? – Pranav Hosangadi Aug 24 '20 at 16:18
  • @PranavHosangadi: Possibly because the `tailf` command isn't available in all operating systems. – martineau Aug 24 '20 at 16:33
  • I have searched explanation on the use of tailf but I don't get how I should use it actually. Than let's say that I have 50 data updated per second. Can I resampled them down to 20/sec? – Fabrizio Aug 25 '20 at 12:46
  • I solved in this way for who is interested. https://stackoverflow.com/questions/63593458/python-boolean-variable-within-generator – Fabrizio Aug 26 '20 at 08:35

1 Answers1

0

I am not that experienced in csv

but take this logic

def writeandRead(one_row):
  with open (path/file.csv,"a"): # it is append .. if  your case write just change from a to w  
    write.row(one_row)

  with open(whateve.csv,"r"):
    red=csv.read #i don't know syntax ... take the logic
  return red

for row in rows: #or you have a lists whatever dictionary 
 print(writeandRead(row))
paull
  • 15
  • 2
  • 7