Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import csv
  2. # open csv
  3. csv_test = 'C:/Users/Duygu Altintas/Desktop/FMRTEST.CSV'
  4. with open(csv_test) as csv_file:
  5. csv_reader = csv.reader(csv_file, delimiter=',')
  6. for row in csv_reader:
  7. # matchHeading = 'SUBCATCHMENTS'
  8. # matchRow = 'CA-1'
  9. # editCol = 4
  10. # valMin = 40
  11. # valMax = 80
  12. # valInterval = 5
  13. matchHeading = row[0]
  14. matchRow = row[1]
  15. editCol = int(row[2])
  16. valMin = int(row[3])
  17. valMax = int(row[4])
  18. valInterval = int(row[5])
  19.  
  20.  
  21. print( matchRow, matchHeading, editCol, valMin, valMax, valInterval )
  22.  
  23.  
  24. for val in range(valMin, valMax, valInterval):
  25. print( val )
  26. outFileName = "{}.{}.{}.inp".format(matchHeading, matchRow, val)
  27.  
  28. swmminput = 'C:/Users/Duygu Altintas/PycharmProjects/FourMileRun/Examples/RUNOFF46_SW5.INP'
  29. outfile = open('c:/Users/Duygu Altintas/PycharmProjects/FourMileRun/Output' + outFileName, 'w+')
  30. currentSection = ""
  31. with open(swmminput, 'r') as inp:
  32. for cnt, line in enumerate(inp):
  33. if line.startswith(';'):
  34. continue
  35. else:
  36. if line.startswith('[') and line.strip().endswith(']'):
  37. currentSection = line.strip()
  38. if matchHeading in currentSection and len(line.split()) > 1:
  39. tokens = line.split()
  40. print( repr( tokens[0].strip()),repr( matchRow ))
  41. if matchRow == tokens[0].strip():
  42. print('here is match')
  43. tokens[editCol] = str(val)
  44. outfile.write("{}\n".format('\t'.join(tokens)))
  45. continue
  46. outfile.write("{}\n".format(line.strip()))
  47. inp.close()
  48. outfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement