Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Variables don't; constants aren't.


devel / comp.lang.python / Re: tail

SubjectAuthor
* Re: tailMRAB
`* Re: tailDennis Lee Bieber
 +* Re: tailMarco Sulla
 |`* Re: tailStefan Ram
 | `- Re: tailDennis Lee Bieber
 +- Re: tailAvi Gross
 `- Re: tailBarry Scott

1
Re: tail

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

 copy mid

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

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: pyt...@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: tail
Date: Fri, 6 May 2022 21:19:48 +0100
Lines: 63
Message-ID: <mailman.329.1651868577.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>
<CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com>
<f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de KiATDR12FrnQVmjRu2Rrzg8vCSSQORO2qMC4klSdXFaA==
Return-Path: <python@mrabarnett.plus.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=plus.com header.i=@plus.com header.b=tJqfJc74;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.014
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'def': 0.04; 'windows,':
0.05; 'utf-8': 0.07; 'from:addr:python': 0.09;
'received:192.168.1.64': 0.09; 'import': 0.15; 'problem.': 0.15;
'"\\n"': 0.16; 'char': 0.16; 'characters.': 0.16; 'encoding,':
0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab':
0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'received:plus.net': 0.16; 'wrote:': 0.16; 'problem': 0.16;
'to:addr:python-list': 0.20; 'maybe': 0.22; 'lines': 0.23;
'tried': 0.26; 'object': 0.26; 'else': 0.27; 'header:User-
Agent:1': 0.30; 'received:192.168.1': 0.32; 'work.': 0.34; 'header
:In-Reply-To:1': 0.34; 'files': 0.36; "it's": 0.37;
'received:192.168': 0.37; 'file': 0.38; 'read': 0.38; 'text':
0.39; 'break': 0.39; 'lower': 0.62; 'received:212': 0.62; 'skip:o
20': 0.63; 'skip:b 10': 0.63; 'extend': 0.64; 'skip:e 20': 0.67;
'little': 0.73; 'skip:f 20': 0.75; 'position': 0.81; 'characters':
0.84; 'sulla': 0.84; 'mode.': 0.89
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1651868389; bh=U+R1ZHEy+qoJ8VSqBww2MVeMLULFpE0nDqfiSgxFdbQ=;
h=Date:Subject:To:References:From:In-Reply-To;
b=tJqfJc74KZbXsdZ734kfR+TgpRmQURc8jThrVAdJ1r5s6jEkCLaFprw4lRdsn9BQ5
2RLN2w2ouw5HvTPH/CswIup5lYoev3HyVKXzj73PbImjJRoSjLgcUKXnUOM6zN8QzN
VpO5f0bdZX6Ri8ZDn8h5x6B63QL7BnbFR3BdSHk4mP8kBMpwrv0YDAL0dJP2aaOEM1
MywTsXf8mKTEqgqsmxGvL4L8gL4DvpHgIwzjtwRiPJHe6xbQEGb0oGLw7+geFTKcnb
oKX1Dhd++VeuBy6RTv6RLHDeHmQTPBJdfGR0TpQFPrX54liTvJ5BqAXOb9f0IKwF7s
Q5GrN0bTH8okg==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=Uo9wis8B c=1 sm=1 tr=0 ts=627582e5
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=-PqB_q5jgSanwETiydIA:9 a=QEXdDO2ut3YA:10
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Content-Language: en-GB
In-Reply-To: <CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com>
X-CMAE-Envelope: MS4xfHlUv+QneSwWBYz1483na3YFT/c6cRrFBDsH7HeVp11X3DBFlx6e5MgvuTABvYnTJnVEVSBKBxuHKNG23PYxwyUR9/2uDfiSVY1YF9/ckAxXNNN8HkIW
Ze7OGWGwo+f1GTFQDLU7blfm/ex4zilnlY6sewvAgwagv+YGw9DcVANgA8bN1arGkbHtBlXaENFS/3IDghkDRz8UIE1IAh75a8c=
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: <f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com>
X-Mailman-Original-References: <CABbU2U-RaZxGqhbWYXCojbXgkH2kKsR0sRNdx3ZtE4_Ycq_GZw@mail.gmail.com>
<Ym8HP9Gt+OE9l+1V@cskk.homeip.net>
<CABbU2U8gaDgqDKqn-GrL6dOs556kVWcU+1OS65k9cfC_3H=FGg@mail.gmail.com>
<CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com>
 by: MRAB - Fri, 6 May 2022 20:19 UTC

On 2022-05-06 20:21, Marco Sulla wrote:
> I have a little problem.
>
> I tried to extend the tail function, so it can read lines from the bottom
> of a file object opened in text mode.
>
> The problem is it does not work. It gets a starting position that is lower
> than the expected by 3 characters. So the first line is read only for 2
> chars, and the last line is missing.
>
> import os
>
> _lf = "\n"
> _cr = "\r"
> _lf_ord = ord(_lf)
>
> def tail(f, n=10, chunk_size=100):
> n_chunk_size = n * chunk_size
> pos = os.stat(f.fileno()).st_size
> chunk_line_pos = -1
> lines_not_found = n
> binary_mode = "b" in f.mode
> lf = _lf_ord if binary_mode else _lf
>
> while pos != 0:
> pos -= n_chunk_size
>
> if pos < 0:
> pos = 0
>
> f.seek(pos)
> chars = f.read(n_chunk_size)
>
> for i, char in enumerate(reversed(chars)):
> if char == lf:
> lines_not_found -= 1
>
> if lines_not_found == 0:
> chunk_line_pos = len(chars) - i - 1
> print(chunk_line_pos, i)
> break
>
> if lines_not_found == 0:
> break
>
> line_pos = pos + chunk_line_pos + 1
>
> f.seek(line_pos)
>
> res = b"" if binary_mode else ""
>
> for i in range(n):
> res += f.readline()
>
> return res
>
> Maybe the problem is 1 char != 1 byte?

Is the file UTF-8? That's a variable-width encoding, so are any of the
characters > U+007F?

Which OS? On Windows, it's common/normal for UTF-8 files to start with a
BOM/signature, which is 3 bytes/1 codepoint.

Re: tail

<343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com>

 copy mid

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

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 06 May 2022 16:10:30 -0500
From: wlfr...@ix.netcom.com (Dennis Lee Bieber)
Newsgroups: comp.lang.python
Subject: Re: tail
Date: Fri, 06 May 2022 17:10:12 -0400
Organization: IISS Elusive Unicorn
Message-ID: <343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com>
References: <CABbU2U-RaZxGqhbWYXCojbXgkH2kKsR0sRNdx3ZtE4_Ycq_GZw@mail.gmail.com> <Ym8HP9Gt+OE9l+1V@cskk.homeip.net> <CABbU2U8gaDgqDKqn-GrL6dOs556kVWcU+1OS65k9cfC_3H=FGg@mail.gmail.com> <CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com> <f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com> <mailman.329.1651868577.20749.python-list@python.org>
User-Agent: ForteAgent/8.00.32.1272
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 29
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-V5W/dX1BgCJAhisG2zWnYC4ONhH21XAGr23BATaNFBjIEhSb1pukOd5pgjpDWO/GMEx5m+Qc2rxZz7s!I8PjCBaGmqEaOQQ1BzGQEsdb+NMTjRR65YTkVVdtfokjQAzivw+5sc3k5LsfURmjzRcOfV/B
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2613
 by: Dennis Lee Bieber - Fri, 6 May 2022 21:10 UTC

On Fri, 6 May 2022 21:19:48 +0100, MRAB <python@mrabarnett.plus.com>
declaimed the following:

>Is the file UTF-8? That's a variable-width encoding, so are any of the
>characters > U+007F?
>
>Which OS? On Windows, it's common/normal for UTF-8 files to start with a
>BOM/signature, which is 3 bytes/1 codepoint.

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.

https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
"""
In text mode, the default when reading is to convert platform-specific line
endings (\n on Unix, \r\n on Windows) to just \n. When writing in text
mode, the default is to convert occurrences of \n back to platform-specific
line endings. This behind-the-scenes modification to file data is fine for
text files, but will corrupt binary data like that in JPEG or EXE files. Be
very careful to use binary mode when reading and writing such files.
"""

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

Re: tail

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

 copy mid

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

 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: Sat, 7 May 2022 15:21:25 +0200
Lines: 9
Message-ID: <mailman.333.1651929724.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>
<CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com>
<f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com>
<mailman.329.1651868577.20749.python-list@python.org>
<343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com>
<CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de AIT+4OIY2hJWTUAu870HQAc1cCcOgmWqWdIPttcyF1lg==
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=fYowsvnE;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.012
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(for': 0.05; '2022': 0.05;
"python's": 0.05; 'string': 0.07; 'cc:addr:python-list': 0.09;
'compute': 0.09; 'cc:no real name:2**0': 0.14; 'from:name:marco
sulla': 0.16; 'wrote:': 0.16; 'uses': 0.19; 'cc:addr:python.org':
0.20; 'option': 0.20; 'sat,': 0.22; 'lines': 0.23; 'cc:2**0':
0.25; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32; 'windows':
0.34; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'using': 0.37; 'received:209.85':
0.37; 'file': 0.38; 'way': 0.38; 'read': 0.38; 'received:209':
0.39; 'text': 0.39; "there's": 0.61; 'mode': 0.62; 'read,': 0.75;
'seek': 0.81; 'position': 0.81; 'marker,': 0.84
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
:cc; bh=VGLaU+puKRErQfsjGsZudcgerMPZgFZnDmcSHnU4qwc=;
b=fYowsvnE/e0fBBmMrND+CQ2v+v38IFVIp9OilpZKsbA9xlwL/rB75ZvAefOERoMk2E
GzEtohV7HIs13XlvJ0UK7yWGlvB0fLFY7kB5MW5wi979HmXVf7Hl0TPakp1p+6nB2edy
fT1XcKf1NJSBNxARCEZRVbhNKtkE07gmPi1sDbOvZ0JH4S1kExYHGVoCSlMaQZ5zthg3
d/hhWcLA6SYEXszPSvgbaVMrtOVGfCb7E1E22MC08VgpYZMUp53PmzGKFmjvR1aP281q
L40BAsdYqyPFJbv4Ugl7VtJXyV2e35/X0kiA+ylCP8XkfTN2Zjo86Sa202tGjozMTARl
q9/Q==
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:cc;
bh=VGLaU+puKRErQfsjGsZudcgerMPZgFZnDmcSHnU4qwc=;
b=JkBtTYLRSdd1jqIYryE29sESdYEr1gpeyA1c7IPgF7f3OvJbgsao89uxg5pFEi/I3U
WYSD8HZ23ETGkbje2KvAoMIbjykoOxI9YwXqLjOPGK/oQx0fCY6QRreMVZlWTFHF/7c5
3j0pUp2RCfC31nCJeLfO3UDdJg+mNbXLK6SGXQ+LSEM7Mcx+pbegGoyYNWMDEslHCWQR
sfq8GkohYh1GW2/RkYo6+NiC829htCfwiMqvvkF3Aah3A94n3MJk80xjPKmsYbIviOFY
GGFhMEpYfEkrHuqe7yW6o/8qcXI4lxF2kY9kBvfCCe261JfHRXeHuq5GLwwJA0K0jVcV
k7dg==
X-Gm-Message-State: AOAM531SE2irHSot/LeMbeIbnuwVEiWu1IG9BrBQFiwbHS5i8UPWyar8
TWHDaRhfz8rkKnD4B8aLWya6Q+/kQSPK634Iu7UtN1AX
X-Google-Smtp-Source: ABdhPJwhEcu2IDLSKT1vUkescxM93x8W3cOKI1F7jWl5l9OCsIMalKQxmQTyiVuBLK3LuJGKqbtVrrnnpiAcB2NPwN8=
X-Received: by 2002:a81:3a57:0:b0:2f1:57ee:c671 with SMTP id
h84-20020a813a57000000b002f157eec671mr6423215ywa.104.1651929721726; Sat, 07
May 2022 06:22:01 -0700 (PDT)
In-Reply-To: <343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com>
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: <CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com>
X-Mailman-Original-References: <CABbU2U-RaZxGqhbWYXCojbXgkH2kKsR0sRNdx3ZtE4_Ycq_GZw@mail.gmail.com>
<Ym8HP9Gt+OE9l+1V@cskk.homeip.net>
<CABbU2U8gaDgqDKqn-GrL6dOs556kVWcU+1OS65k9cfC_3H=FGg@mail.gmail.com>
<CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com>
<f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com>
<mailman.329.1651868577.20749.python-list@python.org>
<343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com>
 by: Marco Sulla - Sat, 7 May 2022 13:21 UTC

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?

Re: tail

<seek-20220507143732@ram.dialup.fu-berlin.de>

 copy mid

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

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: tail
Date: 7 May 2022 13:40:35 GMT
Organization: Stefan Ram
Lines: 35
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <seek-20220507143732@ram.dialup.fu-berlin.de>
References: <CABbU2U-RaZxGqhbWYXCojbXgkH2kKsR0sRNdx3ZtE4_Ycq_GZw@mail.gmail.com> <Ym8HP9Gt+OE9l+1V@cskk.homeip.net> <CABbU2U8gaDgqDKqn-GrL6dOs556kVWcU+1OS65k9cfC_3H=FGg@mail.gmail.com> <CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com> <f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com> <mailman.329.1651868577.20749.python-list@python.org> <343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com> <CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com> <mailman.333.1651929724.20749.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de D/IeJ+Wqb+XSv1EVFWK6wg/svlEWlz4S6oLRM/5y01u8Ov
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 7 May 2022 13:40 UTC

Marco Sulla <Marco.Sulla.Python@gmail.com> writes:
>So there's no way to reliably read lines in reverse in text mode using
>seek and read, but the only option is readlines?

I think, CPython is based on C. I don't know whether
Python's seek function directly calls C's fseek function,
but maybe the following parts of the C standard also are
relevant for Python?

|Setting the file position indicator to end-of-file, as with
|fseek(file, 0, SEEK_END), has undefined behavior for a binary
|stream (because of possible trailing null characters) or for
|any stream with state-dependent encoding that does not
|assuredly end in the initial shift state.
from a footnote in a draft of a C standard

|For a text stream, either offset shall be zero, or offset
|shall be a value returned by an earlier successful call to
|the ftell function on a stream associated with the same file
|and whence shall be SEEK_SET.
from a draft of a C standard

|A text stream is an ordered sequence of characters composed
|into lines, each line consisting of zero or more characters
|plus a terminating new-line character. Whether the last line
|requires a terminating new-line character is implementation-defined.
from a draft of a C standard

This might mean that reading from a text stream that is not
ending in a new-line character might have undefined behavior
(depending on the C implementation). In practice, it might
mean that some things could go wrong near the end of such
a stream.

Re: tail

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

 copy mid

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

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: avigr...@verizon.net (Avi Gross)
Newsgroups: comp.lang.python
Subject: Re: tail
Date: Sat, 7 May 2022 14:01:04 +0000 (UTC)
Lines: 47
Message-ID: <mailman.334.1651932029.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>
<CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com>
<f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com>
<mailman.329.1651868577.20749.python-list@python.org>
<343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com>
<CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com>
<661020750.322747.1651932064781@mail.yahoo.com>
Reply-To: Avi Gross <avigross@verizon.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de SzuMdkpcuCN/9jBZNyLOgg0ilRrmxRAvDaZ/yv82YBiA==
Return-Path: <avigross@verizon.net>
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=verizon.net header.i=@verizon.net header.b=WNjLWsgL;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.090
X-Spam-Evidence: '*H*': 0.82; '*S*': 0.00; '(for': 0.05; '2022': 0.05;
"python's": 0.05; 'random': 0.05; 'string': 0.07; 'byte': 0.09;
'cc:addr:python-list': 0.09; 'compute': 0.09; 'obviously': 0.09;
'log': 0.12; 'url:mailman': 0.15; 'classic': 0.16; 'encoding':
0.16; 'uncommon': 0.16; 'wrote:': 0.16; 'uses': 0.19;
'cc:addr:python.org': 0.20; 'option': 0.20; 'sat,': 0.22;
'tools.': 0.22; 'goal': 0.23; 'lines': 0.23; 'skip:- 10': 0.25;
'url-ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'url:listinfo': 0.25; 'cc:2**0': 0.25; 'url-ip:188.166/16': 0.25;
'fact': 0.28; 'purpose': 0.28; 'sense': 0.28; 'it,': 0.29; 'url-
ip:188/8': 0.31; 'think': 0.32; 'structure': 0.32; 'but': 0.32;
'there': 0.33; 'windows': 0.34; 'header:In-Reply-To:1': 0.34;
'files': 0.36; 'people': 0.36; 'using': 0.37; 'file': 0.38; 'way':
0.38; 'means': 0.38; 'read': 0.38; 'text': 0.39; 'enough': 0.39;
'finding': 0.39; 'beginning': 0.40; 'higher': 0.60; 'to:none':
0.60; 'method': 0.61; "there's": 0.61; 'from:': 0.62; 'to:': 0.62;
'skip:i 20': 0.62; 'mode': 0.62; 'simply': 0.63; 'clear': 0.64;
're:': 0.64; 'your': 0.64; 'years': 0.65; 'back': 0.67; 'heard':
0.67; 'cc:': 0.69; 'obvious': 0.69; 'order.': 0.69; 'too.': 0.70;
'read,': 0.75; 'short,': 0.76; 'sent:': 0.78; 'header:Reply-To:1':
0.79; 'database': 0.80; 'seek': 0.81; 'position': 0.81; 'marker,':
0.84; 'sulla': 0.84; 'widths': 0.84; 'width': 0.91; 'storage':
0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verizon.net; s=a2048;
t=1651932026; bh=5HAdv2tQUkwWdovVtGXvAYycINYTfOaJGJiCMAxWj3I=;
h=Date:From:Reply-To:Cc:In-Reply-To:References:Subject:From:Subject:Reply-To;
b=WNjLWsgLwYg3TwAhMwaSf3LD1r61neaepjy0QK1FEpIWgcdTTACAHolRbynjin83v+cR0M2vAd08Q8QSNGwcrUBNsKPThBhogaa9BmjEpacOwYef1PxJWfO2oOlZEFOIBs4tpYnVGJS9Lb6sLKwDIShBusxanWONGIlJkN4LwDPjKfXPpIWiOWpaTQdL/AW9RQM47ThfExW/N3OoXmcqbMpK5JNp6C9ANA1YAf1u/vGYXCHu4+bQaEzLW083BaGHtN6kAcCdo4WsLrS7myh7Kr6z2iWniQvgOp8FoyYhlssTcnLKdEv8vJBiRlaeLeNrQ/snhub8BKPyBHvPpPSFMQ==
X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
t=1651932026; bh=UiE9xe1ePI/EVh1jw0eGx01uhqhFkFg5Ym8GRkleJMd=;
h=X-Sonic-MF:Date:From:Subject:From:Subject;
b=LDuPJhXCIx6bULKTQjwAHeY9dArv9EOFXFZDTX54IzIXNipOz+ESitGuYkg3KDftnzWsY1r7uVOTZnLqc1caOHf8oUMHihha+9wIR1GgGYAMvj65HE9b+dvnuxjdD1Q/PddQ2gHPprfJBpOXO8vPYJREiKgnm+6rCw3NeBOqmzBO8dWiXQtbOcIJnc1poQg3GVOm9FXZx09ydpvnV1qz9meVJEAGIlYxt5b+BZatx4DShLBPLqvTuep1qQg1YkfQM4AqzxLBVifNFNWZ/f1CWKpNLrcjgUo9axXgC5pv6MvKWwP8zDUcNaQOtAamIo3qX1C3eYlMHMSFBS0Rg9mEbg==
X-YMail-OSG: 6HhN2GUVM1lvCnhOTMAebMWxsLj3rwk4ZDvriy5Ixcf9Dfvyct9ztZoYG3lf5ov
rBpPKbg_R1S8dS.WuYP7IIEmJy6BW2lTtPus__qKAsGKjFqKMaLTUZtziV_J9tFPozwSTzwRtMl.
T4RbpNxJV2PyF19a2S.IreC6aT5P40P0cfiPiD.qH51LiwdROn_Kr.HZ2Ko0GcLGcoT0gKCK0FYj
LuzuLjoxbHaz5j9SMrE96d0BVcAS3cQvN6eMz1O3f2w_ZtQWlVIR0TpKex9Mop.mf0oIywQlLXaB
.PYDmHycOt9nvhlhW4uEbnk2pem7NKQt9JS3.FdZsMif3eXdN2m8tc5YEY2GKOia3q1cGjPhoIGG
YBrjwTlcKqGO2GM7gZkKJWIdgz00fDv2YpHegza8r2dgnIGKyAkLbv5TisWpRXkcN.OJzAQ9YU5L
YQPia63E42YEUqwanS0VJlPPKD5Bu2fW.iVdXnMbdfxTNONuxf0LdXkuY_CwIVIGkSYLmFSix3Jp
zQV_Thx5W_yIjkUar0zbG.GF6kYbA0HHiImeJJRjG1mll.K7lVGU1NLWmXw6ce9FhYRAHzpSFZiZ
ZKbwtZEUxMhv6FZhlth2vF84UwF6g7mh0hdPan1BlP0krlR8YPGYfgnG5f9cK3U3VIpUBbity7Pl
BZZ5_AeasgUmc8jntCNaDGBWINDin9Oq0wTDn33G2VF3ZeGfY0wqcDHt5xBqm_HcFKT4r8snmsTr
Vvlxach0LCiA7QKOfRK0H.rHoAEGrMBVgkIj5yPgDC2718uhBhtd8eUYM4NR.Zh58eWabxILRYEZ
b0hdZbnzGjK_J3t406yM_gT1Mw792ma8iIwRTrclzBCE9Kb1Atw0vPZPOMz83yJiLY2MzsrL38lK
x73gWvNiTlr9EnCeOkxsBu5udpToSdJb6Jez0CnEaWswK9c7B4dPWWBn4CRgjW6kFCTC70MG0iBY
r6PyzEMaUKpzgpMrtUGoIYO1.W8o8tMtD.MMXdfycCVWCIhQSquBo9WrstIkoOl7IIHrnDmBHDuG
5CC0.HUt2xl6Efg66QkHyL5NPsNU_cV0OFdXGagg7XqCoX4GQ_XoPqgOtxU7Ufe9u1tzbxJyv1Oz
LTsggHpvVAiMw7Ecfn6mAcpR72xgOUfnuunM6l5f3nPYQlfp_9Carzr_ZhlMiBo4H9kGZTvdloM0
OksfWerLEU_AwPRCNIAOQshLQRWB96FpIRhSvU7hdbQ4C6k1PhVJIdXlpvhm5IknPEwzY4siDm55
PAR3Y6vJrAmswrB8Rz5GkIunP_jFNwYvFWfQdK3mADfQhxLa19WMdOtTgnZW4uYh_BR2_uDiKyrN
PZ5rCcaZo5rgrwJHAiPowhsyrQM8S0mEDI4c9uhBqQIpRMGuHIcdGTWrSa0YWojBqZZ0_3JeIIn_
VvopXSa2GVpN_DA5PtRCQMSElG6lBAaURraKLKuNrMg48CimgiizecEu1SggJbzbbq0hvk7igMyS
5YY7JuK8tWQlkI2kLFDq.qwP0f0iGrCNfF3_0d_iZ4M8BJXWa8khq8m3rVw3yeEty_Pgln.08FzM
ToLqfJHWumNiI8s7xc6Is7vs3cnCWONwLQJZJ7PL.m8tFTlWN_5OxLAFtkuAUdw7e5X0nOMBkAAL
2M2VzSm3WC8UVXx9Jldf8AgNTjxIQgXrc7A0MzDwDVpG2CsSnR0E0JvCeQBODIbN_fMgG.wZQ6aO
cx6eFpzOfKXhe0ttgEcv402sStVZNG4ZnacLsY_LuhFRHRHCCcO0QUi5GpSpHvu.5IusvH5ey_eb
eDreEPY7d9pl15uO4katyOhxpUoJppcCAn8oVgdDlAItvewPD9E2jMLk1SU2lP7f2lYiy90Y04PA
a4_MyvcrFWgEXXkTkOzpKAXtc77fxjUA_PkCplRwOKFBGKa1fl3miQLssXo2GDSwv7Rwj_07Bthm
SaoWsrdvupq4yVSuEwal9nIqPN.g4BnTev2twvt6wp1E0h6zZHzMoftxHFnz0rv8dCtbccY4TUNX
al5bAhPtsYeGHUU8rKXFJeuru75MMh9bCbeyN42jbn4lBE0tp85ZK9KQHfzhhHTLrlQOMiIb56pt
Qn9JxXN1W_ZT.V.0qiOYPlYR6hSqupZWcZASSsC.qrdBPxoouQlCajdL.rZAT8bDXFM6P3h5t5WS
DN8fK4HpCAMfIjcnh1L3OLhcLxXR4JHZ_mWe72OoxlJhojhyzZuP4E4VmeRGlkTV48ES15_fejCv
5aadY9Oweled_0evzb.qUZZax7UB8hAqgl9xBZZwm
X-Sonic-MF: <avigross@verizon.net>
In-Reply-To: <CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com>
X-Mailer: WebService/1.1.20188 aolwebmail
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <661020750.322747.1651932064781@mail.yahoo.com>
X-Mailman-Original-References: <CABbU2U-RaZxGqhbWYXCojbXgkH2kKsR0sRNdx3ZtE4_Ycq_GZw@mail.gmail.com>
<Ym8HP9Gt+OE9l+1V@cskk.homeip.net>
<CABbU2U8gaDgqDKqn-GrL6dOs556kVWcU+1OS65k9cfC_3H=FGg@mail.gmail.com>
<CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com>
<f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com>
<mailman.329.1651868577.20749.python-list@python.org>
<343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com>
<CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com>
 by: Avi Gross - Sat, 7 May 2022 14:01 UTC

Marco,
I think it was made clear from the start that "text" files in the classic sense have no random access method at any higher level than reading a byte at some offset from the beginning of the file, or back from the end when it has not grown.
The obvious fact is that most of the time the lines are not of fixed widths and you have heard about multiple byte encodings and how the ends of lines can vary.

When files get long enough that just reading them from the start as a whole, or even in chunks, gets too expensive, some people might consider some other method. Log files can go on for years so it is not uncommon to start a new one periodically and have a folder with many of them in some order. To get the last few lines simply means finding the last file and reading it, or if it is too short, getting the penultimate one too.
And obviously a database or other structure might work better which might make each "line" a record and index them.
But there are ways to create your own data that get around this such as using an encoding with a large but fixed width for every character albeit you need more storage space. But if the goal is a general purpose tool, internationalization from ASCII has created a challenge for lots of such tools.

-----Original Message-----
From: Marco Sulla <Marco.Sulla.Python@gmail.com>
To: Dennis Lee Bieber <wlfraed@ix.netcom.com>
Cc: python-list@python.org
Sent: Sat, May 7, 2022 9:21 am
Subject: Re: tail

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?
--
https://mail.python.org/mailman/listinfo/python-list

Re: tail

<2sad7h5q150svigocgmsv7bn8mtjni0kev@4ax.com>

 copy mid

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

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 07 May 2022 12:35:08 -0500
From: wlfr...@ix.netcom.com (Dennis Lee Bieber)
Newsgroups: comp.lang.python
Subject: Re: tail
Date: Sat, 07 May 2022 13:35:09 -0400
Organization: IISS Elusive Unicorn
Message-ID: <2sad7h5q150svigocgmsv7bn8mtjni0kev@4ax.com>
References: <CABbU2U8gaDgqDKqn-GrL6dOs556kVWcU+1OS65k9cfC_3H=FGg@mail.gmail.com> <CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com> <f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com> <mailman.329.1651868577.20749.python-list@python.org> <343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com> <CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com> <mailman.333.1651929724.20749.python-list@python.org> <seek-20220507143732@ram.dialup.fu-berlin.de>
User-Agent: ForteAgent/8.00.32.1272
X-No-Archive: Yes
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 27
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-PVFwNv4a9Atvdz3zivBWlbwY9wabGquFdUR3xNyku0+hRijMacSvY52UeXlHInetylL9Hgbts2vxnd/!JR2ZEX8PnFbEkVq4T6yWun/bvppHurdXSHEXLfzlXOjuXnkOE9aKo0+bggA0AC7pSBTHNV/z
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2454
 by: Dennis Lee Bieber - Sat, 7 May 2022 17:35 UTC

On 7 May 2022 13:40:35 GMT, ram@zedat.fu-berlin.de (Stefan Ram) declaimed
the following:

>
>|For a text stream, either offset shall be zero, or offset
>|shall be a value returned by an earlier successful call to
>|the ftell function on a stream associated with the same file
>|and whence shall be SEEK_SET.
>from a draft of a C standard
>

Which basically translates to:

1) Seek to beginning of file (SEEK_SET, offset 0)
2) Seek to end of file (SEEK_END, offset 0)
3) Seek to previously obtained position (SEEK_SET, offset obtained from a
call to ftell(); for example, perform some reads, perform ftell(),
SEEK_END@0, write/append some data, SEEK_SET@saved-position, continue
reading).

Seeking to computed (SEEK_CUR @ +/-, SEEK_END @ +, SEEK_SET @ +)
positions may be erroneous and/or unreliable.

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

Re: tail

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

 copy mid

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

 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 Scott)
Newsgroups: comp.lang.python
Subject: Re: tail
Date: Sun, 8 May 2022 19:10:30 +0100
Lines: 52
Message-ID: <mailman.349.1652033439.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>
<CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com>
<f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com>
<mailman.329.1651868577.20749.python-list@python.org>
<343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com>
<CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com>
<mailman.333.1651929724.20749.python-list@python.org>
<seek-20220507143732@ram.dialup.fu-berlin.de>
<6AF4F78E-5BE1-429E-9D45-197E441A02DD@barrys-emacs.org>
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\))
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de MdvVjokhyUAUyXF1tYvZvA6xIgpeGJProN0ZaLI2Xurw==
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; 'python?': 0.03; 'stream':
0.04; "python's": 0.05; 'ram': 0.07; 'cc:addr:python-list': 0.09;
'from:addr:barry': 0.09; 'received:217.70': 0.09;
'received:gandi.net': 0.09; 'received:mail.gandi.net': 0.09;
'shift': 0.09; 'writes:': 0.09; 'cc:no real name:2**0': 0.14;
'url:mailman': 0.15; '(because': 0.16; '2022,': 0.16; 'api.':
0.16; 'barry': 0.16; 'cpython': 0.16; 'encoding': 0.16; 'from:addr
:barrys-emacs.org': 0.16; 'from:name:barry scott': 0.16; 'message-
id:@barrys-emacs.org': 0.16; 'practice,': 0.16; 'stream.': 0.16;
'terminating': 0.16; 'to:addr:ram': 0.16; 'to:addr:zedat.fu-
berlin.de': 0.16; 'to:name:stefan ram': 0.16; 'wrote:': 0.16;
'python': 0.16; 'api': 0.17; 'uses': 0.19; 'calls': 0.19;
'cc:addr:python.org': 0.20; 'option': 0.20; 'maybe': 0.22;
'lines': 0.23; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'cc:2**0': 0.25;
'url-ip:188.166/16': 0.25; 'behavior': 0.26; 'binary': 0.26;
'stefan': 0.26; 'function': 0.27; 'expect': 0.28; 'wrong': 0.28;
'url-ip:188/8': 0.31; 'zero': 0.32; 'but': 0.32; 'there': 0.33;
'same': 0.34; 'mean': 0.34; 'header:In-Reply-To:1': 0.34;
'following': 0.35; 'using': 0.37; 'file': 0.38; 'way': 0.38;
'could': 0.38; 'read': 0.38; 'text': 0.39; 'files.': 0.40;
'initial': 0.61; 'shall': 0.61; "there's": 0.61; 'skip:i 20':
0.62; 'mode': 0.62; 'parts': 0.65; 'earlier': 0.67;
'received:217': 0.67; 'sequence': 0.69; 'relevant': 0.73; 'read,':
0.75; 'near': 0.76; 'successful': 0.78; 'returned': 0.81; 'seek':
0.81; 'position': 0.81; 'characters': 0.84; 'composed': 0.84;
'lines,': 0.84; 'ordered': 0.84; 'sulla': 0.84; 'consisting':
0.91; 'suffer': 0.91; 'think,': 0.91
In-Reply-To: <seek-20220507143732@ram.dialup.fu-berlin.de>
X-Mailer: Apple Mail (2.3696.80.82.1.1)
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: <6AF4F78E-5BE1-429E-9D45-197E441A02DD@barrys-emacs.org>
X-Mailman-Original-References: <CABbU2U-RaZxGqhbWYXCojbXgkH2kKsR0sRNdx3ZtE4_Ycq_GZw@mail.gmail.com>
<Ym8HP9Gt+OE9l+1V@cskk.homeip.net>
<CABbU2U8gaDgqDKqn-GrL6dOs556kVWcU+1OS65k9cfC_3H=FGg@mail.gmail.com>
<CABbU2U9SXQ0jANm7JrxOcsM50jkE86-YeMzEwOme_0vhpd9i9A@mail.gmail.com>
<f208b3f0-c987-473a-4c01-38664599ff9e@mrabarnett.plus.com>
<mailman.329.1651868577.20749.python-list@python.org>
<343b7hlfae195bt4inm3sg9es39bd6butk@4ax.com>
<CABbU2U-_Z546umxtnZXL8b1LUERCnyOxYw6osKTvKncOHFkJ3A@mail.gmail.com>
<mailman.333.1651929724.20749.python-list@python.org>
<seek-20220507143732@ram.dialup.fu-berlin.de>
 by: Barry Scott - Sun, 8 May 2022 18:10 UTC

> On 7 May 2022, at 14:40, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>
> Marco Sulla <Marco.Sulla.Python@gmail.com> writes:
>> So there's no way to reliably read lines in reverse in text mode using
>> seek and read, but the only option is readlines?
>
> I think, CPython is based on C. I don't know whether
> Python's seek function directly calls C's fseek function,
> but maybe the following parts of the C standard also are
> relevant for Python?

There is the posix API that and the C FILE API.

I expect that the odities you about NUL chars is all about the FILE
API. As far as I know its the posix API that C Python uses and it
does not suffer from issues with binary files.

Barry

>
> |Setting the file position indicator to end-of-file, as with
> |fseek(file, 0, SEEK_END), has undefined behavior for a binary
> |stream (because of possible trailing null characters) or for
> |any stream with state-dependent encoding that does not
> |assuredly end in the initial shift state.
> from a footnote in a draft of a C standard
>
> |For a text stream, either offset shall be zero, or offset
> |shall be a value returned by an earlier successful call to
> |the ftell function on a stream associated with the same file
> |and whence shall be SEEK_SET.
> from a draft of a C standard
>
> |A text stream is an ordered sequence of characters composed
> |into lines, each line consisting of zero or more characters
> |plus a terminating new-line character. Whether the last line
> |requires a terminating new-line character is implementation-defined.
> from a draft of a C standard
>
> This might mean that reading from a text stream that is not
> ending in a new-line character might have undefined behavior
> (depending on the C implementation). In practice, it might
> mean that some things could go wrong near the end of such
> a stream.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor