Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- #Set input file name
- #Use full directory path
- #InFileName = raw_input("File to open: ")
- InFileName = "test.csv"
- #Open the input file
- InFile = open(InFileName, 'r')
- #Count number of lines in file and print
- RecordCount = len(file(InFileName, 'r').readlines())
- print RecordCount
- #Initialize counter
- LineNumber = 0
- #Loop through each line in file
- for Line in InFile:
- #Remove line-ending characters
- Line = Line.strip('\n').strip('\r')
- #Split into list
- ElementList = Line.split(',')
- if LineNumber > 0:
- #Print the line
- #print LineNumber, ':', ElementList
- #Test for same follicle, need to add elements of list to include
- if ElementList[0:9] == LastLine[0:9]:
- #Add clonesize from LastLine
- #Delete LastLine from output file
- #Add this modified line to output file
- print 'true'
- print ElementList[9]
- print LastLine[9]
- #Add together as integers
- ElementList[9] = LastLine[9] + ElementList[9]
- print ElementList[9]
- else:
- #Don't add anything to anything
- #Add this line to output file
- print 'false'
- #Index the counter
- LineNumber = LineNumber +1
- #Makes new list to compare in next trip through loop, initializes on first pass when if has bypassed the titles
- LastLine = ElementList[:]
- ElementList = [:]
- InFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement