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


Groups > comp.lang.python > #12323

Re: Record seperator

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'string.': 0.04; 'lines.': 0.05; ':-)': 0.06; 'received:verizon.net': 0.07; 'sized': 0.07; 'terry': 0.07; '>>>>': 0.09; 'minus': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'separating': 0.09; 'files.': 0.09; 'def': 0.15; 'read()': 0.16; 'reedy': 0.16; 'roy': 0.16; 'splits': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; '(or': 0.23; 'opens': 0.23; 'pm,': 0.24; 'code': 0.25; 'fine': 0.26; 'loop': 0.28; 'problem': 0.28; 'forgot': 0.29; 'indicated': 0.29; 'yield': 0.29; 'line:': 0.30; "skip:' 10": 0.30; 'least': 0.31; 'to:addr :python-list': 0.33; 'header:User-Agent:1': 0.34; 'fail': 0.34; 'right,': 0.34; 'header:X-Complaints-To:1': 0.35; 'file': 0.36; 'but': 0.37; 'received:org': 0.38; 'steven': 0.38; 'subject:: ': 0.39; 'files,': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'plus': 0.65; 'blank': 0.74; 'biggest': 0.74; 'article,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Record seperator
Date Sat, 27 Aug 2011 20:55:55 -0400
References <slrnj5fo7u.4ra.greymausg@hmaus.org> <mailman.451.1314385354.27778.python-list@python.org> <slrnj5i1g9.581.greymausg@hmaus.org> <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> <roy-F7BDDC.13453127082011@news.panix.com> <mailman.477.1314475482.27778.python-list@python.org> <roy-098B9B.17074827082011@news.panix.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-74-109-121-73.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0
In-Reply-To <roy-098B9B.17074827082011@news.panix.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
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.496.1314493010.27778.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1314493010 news.xs4all.nl 2428 [2001:888:2000:d::a6]:34534
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:12323

Show key headers only | View raw


On 8/27/2011 5:07 PM, Roy Smith wrote:
> In article<mailman.477.1314475482.27778.python-list@python.org>,
>   Terry Reedy<tjreedy@udel.edu>  wrote:
>
>> On 8/27/2011 1:45 PM, Roy Smith wrote:
>>> In article<4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com>,
>>>    Steven D'Aprano<steve+comp.lang.python@pearwood.info>   wrote:
>>>
>>>> open("file.txt")   # opens the file
>>>>    .read()           # reads the contents of the file
>>>>    .split("\n\n")    # splits the text on double-newlines.
>>>
>>> The biggest problem with this code is that read() slurps the entire file
>>> into a string.  That's fine for moderately sized files, but will fail
>>> (or at least be grossly inefficient) for very large files.
>>
>> I read the above as separating the file into paragraphs, as indicated by
>> blank lines.
>>
>> def paragraphs(file):
>>     para = []
>>     for line in file:
>>       if line:
>>         para.append(line)
>>       else:
>>         yield para # or ''.join(para), as desired
>>         para = []
>
> Plus or minus the last paragraph in the file :-)

Or right, I forgot the last line, which is a repeat of the yield after 
the for loop finishes.

-- 
Terry Jan Reedy

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


Thread

Record seperator greymaus <greymausg@mail.com> - 2011-08-26 18:39 +0000
  Re: Record seperator "D'Arcy J.M. Cain" <darcy@druid.net> - 2011-08-26 15:02 -0400
    Re: Record seperator greymaus <greymausg@mail.com> - 2011-08-27 16:59 +0000
      Re: Record seperator Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-28 03:24 +1000
        Re: Record seperator Roy Smith <roy@panix.com> - 2011-08-27 13:45 -0400
          Re: Record seperator ChasBrown <cbrown@cbrownsystems.com> - 2011-08-27 11:40 -0700
          Re: Record seperator Terry Reedy <tjreedy@udel.edu> - 2011-08-27 16:03 -0400
            Re: Record seperator Roy Smith <roy@panix.com> - 2011-08-27 17:07 -0400
              Re: Record seperator Terry Reedy <tjreedy@udel.edu> - 2011-08-27 20:55 -0400
          Re: Record seperator Chris Angelico <rosuav@gmail.com> - 2011-08-28 06:07 +1000
        Re: Record seperator greymaus <greymausg@mail.com> - 2011-08-28 10:03 +0000

csiph-web