[Tutor] Reading every 5th line

Dave Angel davea at ieee.org
Mon Aug 9 12:02:27 CEST 2010



nitin chandra wrote:
> <removed top-post>
>> This may help you get started.
>>
>> FileNames ="FileName01", "FileName02", ..., "FileName24"]
>> for File in FileNames:
>>   List =pen(File, 'r').readlines()
>>   for Start in [[14, "%s-1" % File], [15,"%s-2" % File]]:
>>       OutList =]
>>       for Line in range(Start[0]-1, 3024, 5):
>>           OutList.append(List[Line])
>>       open(("%s.txt" % Start[1]), 'w').writelines(OutList)
>>
>> P.S. My code writing style isn't very conventional.
>>
>>
>>     
Note that three of those lines may be replaced with a slice (untested)

      OutList =]
      for Line in range(Start[0]-1, 3024, 5):
          OutList.append(List[Line])


      OutList = List[Start[0]-1: 3024: 5]





More information about the Tutor mailing list