Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Irregular last line in a text file, was Re: Regular expressions Date: Tue, 03 Nov 2015 16:35:22 +0100 Organization: None Lines: 29 Message-ID: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de fl6e1Xap/oMfBEE25XA1UwcCllx/nLxG0fIZHEUmbgGA== Return-Path: 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; 'subject:text': 0.04; 'false,': 0.07; 'newline': 0.07; 'subject:file': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'satisfy': 0.09; 'files.': 0.13; 'def': 0.13; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:Regular': 0.16; 'subject:expressions': 0.16; 'wrote:': 0.16; 'string': 0.17; 'defined': 0.23; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'subject:last': 0.30; 'skip:s 30': 0.31; 'post': 0.31; 'maybe': 0.33; 'requirement.': 0.33; 'file': 0.34; 'false': 0.35; 'something': 0.35; 'there': 0.36; 'lines': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'end': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'default': 0.61; 'wish': 0.71; 'special': 0.73; 'otten': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd9867.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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:98165 Jussi Piitulainen wrote: > Peter Otten writes: > >> If a "line" is defined as a string that ends with a newline >> >> def ends_in_asterisk(line): >> return False >> >> would also satisfy the requirement. Lies, damned lies, and specs ;) > > Even if a "line" is defined as a string that comes from reading > something like a file with default options, a line may end in > an asterisk. Note that the last line from the file is not a line as defined by me in the above post ;) >>>> [ line.endswith('*') for line in StringIO('rivi*\nrivi*\nrivi*') ] > [False, False, True] I wish there were a way to prohibit such files. Maybe a special value with open(..., newline="normalize") f: assert all(line.endswith("\n") for line in f) to ensure that all lines end with "\n"?