Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: How to read from a file to an arbitrary delimiter efficiently? Date: Sat, 27 Feb 2016 23:18:49 +1100 Lines: 14 Message-ID: References: <56cea44e$0$11128$c3e8da3@news.astraweb.com> <56d17138$0$1605$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de YzZwdvL6TefoFc2PRx1Z+ALoH/j3FzL7RDzA/8dRW9kw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:file': 0.07; 'cc:addr:python-list': 0.09; 'subject:How': 0.09; 'buffer.': 0.09; 'delimiter': 0.09; '"to': 0.16; '*only*': 0.16; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ideally,': 0.16; 'line")': 0.16; 'losing': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'feb': 0.23; 'sat,': 0.23; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.27; 'operations,': 0.27; 'went': 0.28; 'coded': 0.29; 'work.': 0.30; "i'd": 0.31; 'possibly': 0.32; 'class': 0.33; 'received:google.com': 0.35; 'next': 0.35; 'could': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; '(and': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'method': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'subject:from': 0.39; 'rather': 0.39; 'your': 0.60; 'more': 0.63; 'different': 0.63; 'chrisa': 0.84; 'subject:read': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=li09nq6BzIv96mpnScB7qEE0Ejf11MI0gVjW8V7krHI=; b=PyJ9OvIO710abZtFew9pJVE19OFo9JTLuFOKlqrddTbrGYy2LwKID7wx+es0FqfiTN 7bCE6nH8PkiWmUb32jTFteonFZIQwi7ZCqcmxryQC2GQucY/IxFBDpc3ExyfwIDFuG/4 Pzs+cWkP9zdOPivSWvSywRn9ck4c8opar5hqMEL8/lwxcZfAiKIQ5SdA4X0WUfdohKJe KJVVY5RFPPj4CD/o+amHmlsAJ4G9RGvkfl7PZrL/wwXfouPFo/iCKztBVvlQqL9jAswc tfZhLDjHaiYuDCS0jhtiRTO2oeVHeJiK6f7Z+B7h4Lfe/dTnwWSQ9KiVMxmEuqxxoj7R jl6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=li09nq6BzIv96mpnScB7qEE0Ejf11MI0gVjW8V7krHI=; b=LIAPN+s0XndOTfEEMlEZJLBzX/21RlJQSR5gUsjevZqQrJ2O23+4YDSysILDh16y2b p9QaiVmW0vqKyp4F7KiVinCboonXaky670i9CQyOUp5R7uLFLAn0101Jy4h5qABQtH0x irPSTzXbiUcDEzi7jFwJuxy57qonBm6f0EMzG6rxJ/wFNeBRpWEdQBNt+vzyuqyMqJYt 6K1g/r/Y91btE+h4KMdfT75WcoZegB4osSMA+DtbZi0PYIM2ILWzEOLVoqP1XpFWB148 FaCeotJrC4tuuR/y2cNlKmoGs+N6LZVDSp/Ktk02tuoJywymMBGz84A6mkvjHTYe7UrU zsmw== X-Gm-Message-State: AD7BkJL+wNiIvigOjHkZOy8mrD/T1UcwVtKYWWJRSYU1Ej73/j0jYItNmo34wY07nGVwhFpMvLZdO6FgJObCvQ== X-Received: by 10.51.17.34 with SMTP id gb2mr2212744igd.13.1456575529324; Sat, 27 Feb 2016 04:18:49 -0800 (PST) In-Reply-To: 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:103583 On Sat, Feb 27, 2016 at 11:17 PM, Chris Angelico wrote: >> Ideally, I'd rather not over-read at all. I'd like the user to be able to >> swap from "read N bytes" to "read to the next delimiter" (and possibly >> even "read the next line") without losing anything. > > If those are the *only* two operations, you should be able to maintain > your own buffer. And, I started out by thinking "to next delimiter" and "next line" were the same thing with different delimiters, but then went and coded the delimiter so that wouldn't work. Whatevs. If those are the only *three* operations, the same class with one more method could do it. ChrisA