May-10-2017, 06:24 PM
Please help me understand why this doesn't write the count to the status.json file.
import json import os import time import datetime # write the status file data def main(self): string = {"stat":[]} count = 0 while True: try: string["stat"] = count with open("/home/pi/sprinkler/status.json", 'w') as f: json.dump(string, f) print(string) count += 1 if count > 99: count = 0 time.sleep(2) except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) except ValueError: print ("Can't write file status.json") if __name__=="__main__":