Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19223

Re: Splitting a file from specific column content

Date 2012-01-22 16:56 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: Splitting a file from specific column content
References <e1f0636a-195c-4fbb-931a-4d619d5f0d18@g27g2000yqa.googlegroups.com> <4F1C2915.6050609@mrabarnett.plus.com> <mailman.4924.1327246798.27778.python-list@python.org> <849e46d1-b3bb-481d-8a8e-17cb51b0523f@cf6g2000vbb.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4928.1327251361.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 22/01/2012 16:17, Yigit Turgut wrote:
[snip]
> On Jan 22, 5:39 pm, Arnaud Delobelle<arno...@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")
]

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Splitting a file from specific column content Yigit Turgut <y.turgut@gmail.com> - 2012-01-22 06:32 -0800
  Re: Splitting a file from specific column content Roy Smith <roy@panix.com> - 2012-01-22 09:45 -0500
    Re: Splitting a file from specific column content Roy Smith <roy@panix.com> - 2012-01-22 14:26 -0500
    Re: Splitting a file from specific column content Tim Chase <python.list@tim.thechases.com> - 2012-01-22 13:34 -0600
    Re: Splitting a file from specific column content Roy Smith <roy@panix.com> - 2012-01-22 14:37 -0500
      Re: Splitting a file from specific column content Yigit Turgut <y.turgut@gmail.com> - 2012-01-22 12:16 -0800
  Re: Splitting a file from specific column content MRAB <python@mrabarnett.plus.com> - 2012-01-22 15:19 +0000
  Re: Splitting a file from specific column content Arnaud Delobelle <arnodel@gmail.com> - 2012-01-22 15:39 +0000
    Re: Splitting a file from specific column content Yigit Turgut <y.turgut@gmail.com> - 2012-01-22 08:17 -0800
      Re: Splitting a file from specific column content MRAB <python@mrabarnett.plus.com> - 2012-01-22 16:56 +0000
        Re: Splitting a file from specific column content Yigit Turgut <y.turgut@gmail.com> - 2012-01-22 09:47 -0800
    Re: Splitting a file from specific column content Eelco <hoogendoorn.eelco@gmail.com> - 2012-01-22 12:43 -0800
  Re: Splitting a file from specific column content MRAB <python@mrabarnett.plus.com> - 2012-01-22 16:09 +0000
  Re: Splitting a file from specific column content Arnaud Delobelle <arnodel@gmail.com> - 2012-01-22 19:58 +0000
  Re: Splitting a file from specific column content MRAB <python@mrabarnett.plus.com> - 2012-01-22 20:55 +0000

csiph-web