Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

One person's error is another person's data.


devel / comp.lang.python / Re: tail

SubjectAuthor
o Re: tailMarco Sulla

1
Re: tail

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: Marco.Su...@gmail.com (Marco Sulla)
Newsgroups: comp.lang.python
Subject: Re: tail
Date: Mon, 2 May 2022 21:40:26 +0200
Lines: 54
Message-ID: <mailman.301.1651520465.20749.python-list@python.org>
References: <CABbU2U-RaZxGqhbWYXCojbXgkH2kKsR0sRNdx3ZtE4_Ycq_GZw@mail.gmail.com>
<Ym8HP9Gt+OE9l+1V@cskk.homeip.net>
<CABbU2U8gaDgqDKqn-GrL6dOs556kVWcU+1OS65k9cfC_3H=FGg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de V+CWqh4A69zJoOOPOzQF1Atz5Nl3bwIG6PSac5MIg99A==
Return-Path: <elbarbun@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=Y1rKzQbC;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.043
X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'this:': 0.03; '2022':
0.05; 'received:209.85.219': 0.09; '-1:': 0.16; '3.3': 0.16;
'cameron': 0.16; 'from:name:marco sulla': 0.16; 'simpson': 0.16;
'wrote:': 0.16; 'instead': 0.17; 'to:addr:python-list': 0.20;
'maybe': 0.22; 'code': 0.23; 'run': 0.23; "i'd": 0.24; 'seems':
0.26; 'tried': 0.26; 'expect': 0.28; 'think': 0.32; 'empty': 0.32;
'message-id:@mail.gmail.com': 0.32; 'unless': 0.32; '100': 0.33;
'same': 0.34; 'header:In-Reply-To:1': 0.34; 'received:google.com':
0.34; 'yes,': 0.35; 'from:addr:gmail.com': 0.35; 'mon,': 0.36;
'special': 0.37; "it's": 0.37; 'received:209.85': 0.37; 'file':
0.38; 'received:209': 0.39; 'text': 0.39; 'break': 0.39;
'something': 0.40; 'want': 0.40; 'skip:o 20': 0.63; 'range': 0.64;
'position': 0.81; 'inclined': 0.84; 'positions:': 0.84; 'sulla':
0.84; 'body.': 0.91; 'duplicate': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=i4Mdc8PYtwVkWpurZpfTgHH7/N3I9Q1I/uDWSw7WxuE=;
b=Y1rKzQbC69w4HPBWTb3+sq/MyBomvRBivc/ZDv0Ofq7g+1pOmSx2iacCaNlO+i+BZ5
XLmyMgsiOt/sp9OU0XYWMUWOppJm7W0Zj6eRhWNsKRZ9gTfQ95zBYp6JJwYKk+APWLk9
lIfOOlEhJI3VUOIMp+ytD8KkkD1fmbySaQoHlcu4WolJItGiFd5+QVI8DoWuqLySuORd
g71ppe4lZmXF50PlcHxscjRMKYublx+l8ZNSQWMWRcCWet9Bv3zgkrvXFKvF7FAYu2Ve
qPRI2vCn0k3QaAXjAXJx6KOIEIXVrBlv8CMQTTFAJeTKc/iVyd8ztDIbd4pV1zQIrXyD
iXYA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=i4Mdc8PYtwVkWpurZpfTgHH7/N3I9Q1I/uDWSw7WxuE=;
b=vgc3q1S4XuYfGcq5ug/Rxgv2qu05dqTdE/b+t33qCr0k1SM9yZ0yGhPlfUTuQBEtXT
9PQoKGraIHUdklbW0eNg67BxFH/ktg5IP7cx2OHucwuagUUGrl1RWEfiPL8qgi0SopvC
50Io+7FXoZssIiPqoE5K0/vnK/oZjodEhABp5Te+OZnLVWdrJPTXWDBq/ByM6TjBGELU
u93bK27X2c1HvFzC2jx+sYZfvgIw0dkFFuqsZhhoSE0Gs+9SaQbqlMoeO3FtAraMtC7v
ljgwctmCIg859In7S7rXcYvGrk6en327nRkxEZggMBrky+nTlD3UXJmcw5966UIP4uNZ
0lTQ==
X-Gm-Message-State: AOAM530dMLjVKKmTjflII0YrzBBwt7Xs5XI/zg1P02Z0dm54gwbNB6ln
PVuaeALhsdLXEbcIpcnQXXxBAoOMcV8sMhZTNQT4RdNf
X-Google-Smtp-Source: ABdhPJz/TjpyR1DCwUNXn4z4AfwiVgS2UixcMoCRRfsm/pqhp9YGL0mcfhaHZbLuwYl+yy2YFzN8w9NFgmXyVXFnNtY=
X-Received: by 2002:a25:fc6:0:b0:649:96cc:1213 with SMTP id
189-20020a250fc6000000b0064996cc1213mr4051009ybp.119.1651520462986; Mon, 02
May 2022 12:41:02 -0700 (PDT)
In-Reply-To: <Ym8HP9Gt+OE9l+1V@cskk.homeip.net>
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: <CABbU2U8gaDgqDKqn-GrL6dOs556kVWcU+1OS65k9cfC_3H=FGg@mail.gmail.com>
X-Mailman-Original-References: <CABbU2U-RaZxGqhbWYXCojbXgkH2kKsR0sRNdx3ZtE4_Ycq_GZw@mail.gmail.com>
<Ym8HP9Gt+OE9l+1V@cskk.homeip.net>
 by: Marco Sulla - Mon, 2 May 2022 19:40 UTC

On Mon, 2 May 2022 at 00:20, Cameron Simpson <cs@cskk.id.au> wrote:
>
> On 01May2022 18:55, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
> >Something like this is OK?
> [...]
> >def tail(f):
> > chunk_size = 100
> > size = os.stat(f.fileno()).st_size
>
> I think you want os.fstat().

It's the same from py 3.3

> > chunk_line_pos = -1
> > pos = 0
> >
> > for pos in positions:
> > f.seek(pos)
> > chars = f.read(chunk_size)
> > chunk_line_pos = chars.rfind(b"\n")
> >
> > if chunk_line_pos != -1:
> > break
>
> Normal text file _end_ in a newline. I'd expect this to stop immediately
> at the end of the file.

I think it's correct. The last line in this case is an empty bytes.

> > if chunk_line_pos == -1:
> > nbytes = pos
> > pos = 0
> > f.seek(pos)
> > chars = f.read(nbytes)
> > chunk_line_pos = chars.rfind(b"\n")
>
> I presume this is because unless you're very lucky, 0 will not be a
> position in the range(). I'd be inclined to avoid duplicating this code
> and special case and instead maybe make the range unbounded and do
> something like this:
>
> if pos < 0:
> pos = 0
> ... seek/read/etc ...
> if pos == 0:
> break
>
> around the for-loop body.

Yes, I was not very happy to duplicate the code... I have to think about it.

> Seems sane. I haven't tried to run it.

Thank you ^^


devel / comp.lang.python / Re: tail

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor