Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. #Set input file name
  4. #Use full directory path
  5. #InFileName = raw_input("File to open: ")
  6. InFileName = "test.csv"
  7. #Open the input file
  8. InFile = open(InFileName, 'r')
  9.  
  10. #Count number of lines in file and print
  11. RecordCount = len(file(InFileName, 'r').readlines())
  12. print RecordCount
  13.  
  14. #Initialize counter
  15. LineNumber = 0
  16.  
  17. #Loop through each line in file
  18. for Line in InFile:
  19.    
  20.     #Remove line-ending characters
  21.     Line = Line.strip('\n').strip('\r')
  22.     #Split into list
  23.     ElementList = Line.split(',')
  24.    
  25.     if LineNumber > 0:
  26.         #Print the line
  27.         #print LineNumber, ':', ElementList
  28.         #Test for same follicle, need to add elements of list to include
  29.         if ElementList[0:9] == LastLine[0:9]:
  30.             #Add clonesize from LastLine
  31.             #Delete LastLine from output file
  32.             #Add this modified line to output file
  33.             print 'true'
  34.             print ElementList[9]
  35.             print LastLine[9]
  36.             #Add together as integers
  37.             ElementList[9] = LastLine[9] + ElementList[9]
  38.             print ElementList[9]
  39.         else:
  40.             #Don't add anything to anything
  41.             #Add this line to output file
  42.             print 'false'
  43.     #Index the counter
  44.     LineNumber = LineNumber +1
  45.     #Makes new list to compare in next trip through loop, initializes on first pass when if has bypassed the titles
  46.     LastLine = ElementList[:]
  47.     ElementList = [:]
  48.  
  49. InFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement