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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'callable': 0.09; 'from:addr:python': 0.09; 'lines:': 0.09; 'sections': 0.13; 'subject:file': 0.13; '"w")': 0.16; 'commas:': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr :python-list': 0.16; 'wrote:': 0.16; 'jan': 0.19; '(but': 0.21; 'header:In-Reply-To:1': 0.22; 'end,': 0.23; 'somehow': 0.23; 'pm,': 0.26; 'variable': 0.27; 'lines': 0.30; '22,': 0.30; 'typeerror:': 0.30; 'break': 0.32; 'header:User-Agent:1': 0.33; 'to:addr:python-list': 0.33; 'object': 0.33; 'received:84': 0.34; 'reply-to:addr:python.org': 0.34; 'especially': 0.35; 'skip:" 10': 0.36; 'but': 0.37; 'skip:o 20': 0.38; 'subject:from': 0.39; 'missing': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'got': 0.40; 'more': 0.61; 'due': 0.66; 'dealing': 0.68; 'header :Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'subject:content': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=J8QoHXbS c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=FFsdPcU1_MIA:10 a=A2dWweJ9qr0A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=pGLkceISAAAA:8 a=j8BOxvSj_PVkAeQXLqcA:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Sun, 22 Jan 2012 16:56:21 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1
MIME-Version 1.0
To python-list@python.org
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>
In-Reply-To <849e46d1-b3bb-481d-8a8e-17cb51b0523f@cf6g2000vbb.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4928.1327251361.27778.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1327251361 news.xs4all.nl 6945 [2001:888:2000:d::a6]:52068
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19223

Show key headers only | 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