Splitting a file from specific column content

Yigit Turgut y.turgut at gmail.com
Sun Jan 22 12:47:04 EST 2012


On Jan 22, 6:56 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
> 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")
> ]

Thank you.



More information about the Python-list mailing list