May-10-2017, 11:17 PM
Okay, thank you to all. Here is the corrected code with a call to main. The problem was I inadvertently left out the call to main when I posted my code, but it was actually in my code. I also remove the self as suggested.
Now, why doesn't this code put data into the status.json file, but it does send the code to the terminal via the print command??
Now, why doesn't this code put data into the status.json file, but it does send the code to the terminal via the print command??
import json import os import time import datetime # write the status file data def main(): string = {"stat":[]} count = 0 while True: try: string["stat"] = count with open("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__": main()