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.pyt...@gmail.com>
To: Dennis Lee Bieber <wlfr...@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 <wlfr...@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
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to