toWriteTest.py 1.0KB

1234567891011121314151617181920212223242526272829303132333435
  1. def writeHeaderstoNewTSV(fileName,headers):
  2. """
  3. Writes the headers to the first line of the .tsv file
  4. Args:
  5. fileName (String): Name of the destination file, ex: "data.tsv"
  6. headers (List(String)): Headers to be written, ex: ["header1","header2"....]
  7. """
  8. assert fileName[-4:] ==".tsv", "fileName must be '.tsv' file not '%s'" %(fileName)
  9. f = open (fileName,"w")
  10. for headerIndex in range(len(headers)):
  11. if headerIndex!=len(headers)-1:
  12. # write header along with\t
  13. f.write(headers[headerIndex]+"\t")
  14. else:
  15. # write last word along with\n
  16. f.write(headers[len(headers)-1]+"\n")
  17. f.close()
  18. writeHeaderstoNewTSV("FlaskTest/static/data/commits_by_author.tsv",["date","author1","author2","author3","author4","author5","author6","author7"])
  19. a= open("FlaskTest/static/data/commits_by_author.tsv","r")
  20. print (a.readlines())
  21. # conversion from space to tsv for fallback if all else fails
  22. # sed 's/ /\t/g' file.dat > file.tsv
  23. # ./gitstats ~/Desktop/tony_gitstats/gitstats/Tools_Portal_TESTING/ ~/Desktop/tony_gitstats/gitstats/output_test