Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jussi Piitulainen Newsgroups: comp.lang.python Subject: Re: Irregular last line in a text file, was Re: Regular expressions Date: Tue, 03 Nov 2015 18:42:20 +0200 Organization: A noiseless patient Spider Lines: 31 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=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="305c68510616a2e7ac08bcd2ff1598bd"; logging-data="26297"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fBDWUvIZ3pM2KMs8yAp/S0BtY2gN/OYc=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:qMOVlICmkxpYziRVol8Tb3BrbJg= sha1:MBMUj3o5iIxZcLNzzQP+rQS4ih8= Xref: csiph.com comp.lang.python:98174 Peter Otten writes: > 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 ;) Noted. >>>>> [ 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"? I'd like that. It should be the default.