Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Wolfgang Maier Newsgroups: comp.lang.python Subject: Re: How to read from a file to an arbitrary delimiter efficiently? Date: Thu, 25 Feb 2016 08:37:14 +0100 Lines: 14 Message-ID: References: <56cea44e$0$11128$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de /d/NW6P1+y0uY8CDQ0MqSgh4CJGHpp0/8QUvilV89vEQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:file': 0.07; 'subject:How': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sake': 0.09; '(small)': 0.16; '07:50,': 0.16; 'attempt.': 0.16; 'discusses': 0.16; 'example).': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'snippets': 0.16; 'wrote:': 0.16; 'header :In-Reply-To:1': 0.24; 'url:bugs': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'received:132': 0.29; 'code': 0.30; 'certainly': 0.30; 'problem': 0.33; 'url:python': 0.33; "d'aprano": 0.33; 'lets': 0.33; 'steven': 0.33; '(for': 0.34; 'there': 0.36; 'url:org': 0.36; 'alone': 0.36; 'faster': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:org': 0.37; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'your': 0.60; 'exercise,': 0.84; 'subject:read': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 132.230.195.61 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: <56cea44e$0$11128$c3e8da3@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103482 On 25.02.2016 07:50, Steven D'Aprano wrote: > I have a need to read to an arbitrary delimiter, which might be any of a > (small) set of characters. For the sake of the exercise, lets say it is > either ! or ? (for example). > You are not alone with your need. http://bugs.python.org/issue1152248 discusses the problem and has some code snippets that you may be interested in. While there is no trivial solution there are certainly faster ways than your first attempt. Wolfgang