joseleeph

Untitled

Dec 8th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. from sys import argv, exit
  2. import csv
  3. import re
  4. if len(argv) < 3:
  5. print("mising command-line argument")
  6. exit(1)
  7.  
  8. #pattern1 = re.compile(r'AGAT')
  9. #pattern2 = re.compile(r'AATG')
  10. #pattern3 = re.compile(r'TATC')
  11. # pattern = re.compile(r'contents[i:j]')
  12.  
  13. with open(argv[1],"r") as file:
  14. count = 0
  15. contents = file.read()
  16.  
  17. i = 0
  18. j = 4
  19. while contents[i:j]:
  20. span = contents[i:j]
  21. repcount = 1
  22. while contents[i+4:j+4] == span:
  23. repcount += 1
  24. i += 4
  25. j += 4
  26. #if repcount != 0:
  27. if repcount > 1:
  28. print("span " + span + " repeats " + str(repcount) + " times")
  29. i += 4
  30. j += 4
  31. else:
  32. i += 4
  33. j += 4
  34.  
  35.  
  36. #index = 0 ### these lines won't recognize header, because it's declared in the next open statement
  37. #for headervalue in header: # for each value in the header
  38. #index += 1 # keep track of which index in the line you are looking at
  39. #if headervalue == span: # if the value in the header matches the span that is looking to be matched
  40. #data = [row for row in contents] # look at each row of the
  41. #if int(data[index]) == repcount:
  42. #print("possible match is named " + data[0])
  43.  
  44. with open(argv[2],"r") as csvfile:
  45. csvcontents = csv.reader(csvfile)
  46. header = next(csvcontents) # look up what next is doing again
  47. print("seeing what the next() function does by assigning it to header")
  48. print("printing header")
  49. print(header) ## assign header into a list
  50.  
  51. data = [row for row in csvcontents]
  52. print("printing data[0]")
  53.  
  54. # this line causes the program to crash, saying
  55. # valueError: invalid literal for int() with base 10: 'Neville'
  56.  
  57. print(data[0]) # why don't lit let me print the name stored at data[0]?
  58. print("printing 1 line at a time")
  59. i = 0
  60. while i < len(data):
  61. print(data[i])
  62. i += 1
  63. print("print(data[15][2]) prints: ")
  64. print(int(data[15][2]))
  65.  
  66. print("print(data[15][1]) prints: ")
  67. print(int(data[15][1]))
  68.  
  69. print("print(data[15][0]) prints: ")
  70.  
  71.  
  72. print("header[1] prints: ")
  73. print(header[1])
  74.  
  75. #print("printing everything in the csv file: ")
  76. #print(data)
  77.  
Advertisement
Add Comment
Please, Sign In to add comment