Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

GIVE: Support the helpless victims of computer error.


devel / comp.lang.python / Re: tail

SubjectAuthor
o Re: tailBarry

1
Re: tail

<mailman.335.1651932502.20749.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18171&group=comp.lang.python#18171

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: bar...@barrys-emacs.org (Barry)
Newsgroups: comp.lang.python
Subject: Re: tail
Date: Sat, 7 May 2022 15:08:14 +0100
Lines: 34
Message-ID: <mailman.335.1651932502.20749.python-list@python.org>
References: <CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com>
<60454E09-0ADA-4881-A84B-6C11397D244F@barrys-emacs.org>
Mime-Version: 1.0 (1.0)
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de /9n2IalatJZx0PhB1GhhTQLE9dUobnskU+X1nn0V9dpQ==
Return-Path: <barry@barrys-emacs.org>
X-Original-To: Python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(for': 0.05; '2022': 0.05;
"python's": 0.05; 'string': 0.07; 'bin': 0.09; 'cc:addr:python-
list': 0.09; 'compute': 0.09; 'from:addr:barry': 0.09;
'received:217.70': 0.09; 'received:gandi.net': 0.09;
'received:mail.gandi.net': 0.09; 'cc:no real name:2**0': 0.14;
'url:mailman': 0.15; '2022,': 0.16; 'barry': 0.16; 'classic':
0.16; 'from:addr:barrys-emacs.org': 0.16; 'message-id:@barrys-
emacs.org': 0.16; 'wrote:': 0.16; 'uses': 0.19; 'figure': 0.19;
'cc:addr:python.org': 0.20; 'option': 0.20; 'mac': 0.22; 'sat,':
0.22; 'cc:2**1': 0.23; 'lines': 0.23; 'url-ip:188.166.95.178/32':
0.25; 'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'url-
ip:188.166/16': 0.25; 'url-ip:188/8': 0.31; 'returning': 0.32;
'split': 0.32; 'but': 0.32; 'windows': 0.34; 'header:In-Reply-
To:1': 0.34; 'handling': 0.35; 'cases': 0.36; 'using': 0.37;
'hard': 0.37; 'file': 0.38; 'way': 0.38; 'read': 0.38; 'text':
0.39; 'handle': 0.39; 'use': 0.39; "there's": 0.61; 'mode': 0.62;
'once': 0.63; 'received:217': 0.67; 'care': 0.71; 'read,': 0.75;
'seek': 0.81; 'position': 0.81; 'decode': 0.84; 'marker,': 0.84;
'os.': 0.84; 'sulla': 0.84
In-Reply-To: <CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com>
X-Mailer: iPad Mail (19E258)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://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: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <60454E09-0ADA-4881-A84B-6C11397D244F@barrys-emacs.org>
X-Mailman-Original-References: <CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com>
 by: Barry - Sat, 7 May 2022 14:08 UTC

> On 7 May 2022, at 14:24, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
>
> On Sat, 7 May 2022 at 01:03, Dennis Lee Bieber <wlfraed@ix.netcom..com> wrote:
>>
>> Windows also uses <cr><lf> for the EOL marker, but Python's I/O system
>> condenses that to just <lf> internally (for TEXT mode) -- so using the
>> length of a string so read to compute a file position may be off-by-one for
>> each EOL in the string.
>
> So there's no way to reliably read lines in reverse in text mode using
> seek and read, but the only option is readlines?

You need to handle the file in bin mode and do the handling of line endings and encodings yourself. It’s not that hard for the cases you wanted.
Figure out which line ending is in use from the CR LF, LF, CR.
Once you have a line decode it before returning it.

The only OS I know that used CR was Classic Mac OS.
If you do not care about that then you can split on NL and strip any trailing CR.

Barry

> --
> https://mail.python.org/mailman/listinfo/python-list
>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor