Overwrite previous live data. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Overwrite previous live data. (/thread-30670.html) |
Overwrite previous live data. - Makada - Oct-30-2020 Hi, I am trying to output the current code, which is working ok. But i want the output to overwrite previous data instead of append. import requests import csv import time import schedule from time import sleep import sys import csv import io starttime=time.time() def task(): with io.open('C:\\Campbellsci\\LoggerNet\\CR1000_Public.dat') as f: reader = csv.reader(f, delimiter=',') for field in reader: a = (field[6]) print(a) while True: try: task() time.sleep(0.25 - time.time() % 0.25) refresh() except: pass time.sleep(0) else: time.sleep(0) refresh()Here is the output: Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> ================== RESTART: C:\Users\Makada\Desktop\cr1000.py ================== 11.38377 11.38377 11.07566 11.07566 10.79836 10.49026 10.42863 10.42863 10.15134 RE: Overwrite previous live data. - snippsat - Oct-31-2020 (Oct-30-2020, 10:38 PM)Makada Wrote: But i want the output to overwrite previous data instead of appendOverwrite and append may mot be the right wording here,as you only print the output. So can clean the screen cls (Window),then only show new data.Also nice to have a way to exit out of loop eg KeyboardInterrupt .So can write a refresh function. import requests import time import schedule from time import sleep import sys import csv import io from os import system, name def refresh(): # Windows if name == 'nt': _ = system('cls') # Mac and linux(here, os.name is 'posix') else: _ = system('clear') starttime=time.time() def task(): with io.open('Mynew.csv') as f: reader = csv.reader(f, delimiter=',') for field in reader: a = (field[1]) print(a) while True: try: task() time.sleep(7 - time.time() % 3) refresh() except KeyboardInterrupt: sys.exit() else: refresh()As you also have import schedule schedule installed,then can it better to use it to do schedule than calculate with time.time and time.sleep .
RE: Overwrite previous live data. - Makada - Nov-07-2020 Hi, thanks for the input. I get an new window every update... |