PyNE work done for Rachel Slaybaugh at UC Berkeley. http://pyne.io/

compare.py 850B

1234567891011121314151617181920212223242526272829303132
  1. import csv
  2. import itertools
  3. var = "extra"
  4. file1 = open(var + ".csv", "rb")
  5. file2 = open("/Users/clayshieh/Documents/MATLAB/" + var + "_m.txt", "rb")
  6. r1 = csv.reader(file1)
  7. r2 = csv.reader(file2)
  8. row_count1 = sum(1 for row in r1)
  9. row_count2 = sum(1 for row in r2)
  10. if row_count1 != row_count2:
  11. print "Actual has " + str(row_count1) + " rows Expected has " + str(row_count2) + "rows."
  12. file1.close()
  13. file2.close()
  14. file1 = open(var + ".csv", "rb")
  15. file2 = open("/Users/clayshieh/Documents/MATLAB/" + var + "_m.txt", "rb")
  16. reader1 = csv.reader(file1)
  17. reader2 = csv.reader(file2)
  18. row = 0
  19. for lhs, rhs in zip(reader1, reader2):
  20. column = 0
  21. for lh, rh in zip(lhs, rhs):
  22. if abs(float(lh) - float(rh)) >= 1e-10:
  23. print "Actual: " + str(lh) + " Expected: " + str(rh) + " at: (" + str(row) + "," + str(column) + ")"
  24. column += 1
  25. row += 1
  26. print row