I am trying to write a file in python so that it saves the latest information read from the serial port. I tried several different methods and read several different messages, but the file continues to write information again and again, without overwriting the previous record.
import serial ser=serial.Serial('/dev/ttyUSB0',57600) target=open( 'wxdata' , 'w+' ) with ser as port, target as outf: while 1: target.truncate() outf.write(ser.read)) outf.flush()
I have a weather station that transmits data wirelessly to a raspberry pi, I just want one line of current data to be saved in the file. right now it just continues the loop and adds it over and over. Any help would be greatly appreciated.
source share