Splitting a file from specific column content

MRAB python at mrabarnett.plus.com
Sun Jan 22 11:56:21 EST 2012


On 22/01/2012 16:17, Yigit Turgut wrote:
[snip]
> On Jan 22, 5:39 pm, Arnaud Delobelle<arno... at gmail.com>  wrote:
[snip]
>>  Or more succintly (but not tested):
>>
>>  sections = [
>>      ("3", "section_1")
>>      ("5", "section_2")
>>      ("\xFF", "section_3")
>>  ]
>>
>>  with open(input_path) as input_file:
>>      lines = iter(input_file)
>>      for end, path in sections:
>>          with open(path, "w") as output_file:
>>              for line in lines:
>>                  if line>= end:
>>                      break
>>                  output_file.write(line)
>>
>>  --
>>  Arnaud
>
> Good idea. Especially when dealing with variable numbers of sections.
> But somehow  I got ;
>
>      ("5", "section_2")
> TypeError: 'tuple' object is not callable
>
That's due to missing commas:

sections = [
     ("3", "section_1"),
     ("5", "section_2"),
     ("\xFF", "section_3")
]



More information about the Python-list mailing list