SHARE
TWEET

Untitled

a guest Dec 10th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def log_data(data, filename="data.csv"):
  2.     names = sorted(data.keys())
  3.  
  4.     isNewFile = False
  5.  
  6.     with open(filename, "r+") as file:
  7.         if file.read() == "":
  8.             isNewFile = True
  9.  
  10.     print(isNewFile)
  11.  
  12.     with open(filename, "a+") as file:
  13.         if isNewFile:
  14.             file.write(",".join([name for name in names]))
  15.             file.write("\n")
  16.  
  17.         file.write(",".join([str(data[name]) for name in names]))
  18.         file.write("\n")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top