[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-26 Thread Chris Angelico
On Fri, 27 May 2022 at 12:01, Stephen J. Turnbull wrote: > > Chris Angelico writes: > > > If I'm reading this correctly, the result from f.tell() has enough > > information to reconstruct a position within a hypothetical array > > of code points contained within the file (that is to say - if yo

[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-26 Thread Stephen J. Turnbull
Chris Angelico writes: > If I'm reading this correctly, the result from f.tell() has enough > information to reconstruct a position within a hypothetical array > of code points contained within the file (that is to say - if you > read the entire file into a string, f.tell() returns something t

[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-26 Thread Chris Angelico
On Thu, 26 May 2022 at 22:07, Eryk Sun wrote: > > On 5/26/22, Steven D'Aprano wrote: > > > > If you seek() to position 4, say, the results will be unpredictable but > > probably not anything good. > > > > In other words, the tell() and seek() cookies represent file positions > > in **bytes**, eve

[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-26 Thread Eryk Sun
On 5/26/22, Steven D'Aprano wrote: > > If you seek() to position 4, say, the results will be unpredictable but > probably not anything good. > > In other words, the tell() and seek() cookies represent file positions > in **bytes**, even though we are reading or writing a text file. To clarify the

[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-26 Thread Steven D'Aprano
On Tue, May 24, 2022 at 04:31:13AM -, mguin...@gmail.com wrote: > seek() and tell() works with opaque values, called cookies. > This is close to low level details, but it is not pythonic. Even after reading the issue you linked to, I am not sure I understand either the issue, or your suggest

[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-26 Thread Steven D'Aprano
On Thu, May 26, 2022 at 08:28:24PM +1000, Steven D'Aprano wrote: > Narrow builds were UCS-2; wide builds were UTC-32. To be more precise, narrow builds were sort of a hybrid between an incomplete version of UTF-16 and a superset of UCS-2. Like UTF-16, if your code point was above U+, it wou

[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-26 Thread Steven D'Aprano
On Wed, May 25, 2022 at 06:16:50PM +0900, Stephen J. Turnbull wrote: > mguin...@gmail.com writes: > > > There should be a safer abstraction to these two basic functions. > > There is: TextIOBase.read, then treat it as an array of code units > (NOT CHARACTERS!!) No need to shout :-) Reading the

[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-26 Thread Eryk Sun
On 5/26/22, Christopher Barker wrote: > IIRC, there were two builds- 16 and 32 bit Unicode. But it wasn’t UTF16, it > was UCS-2. In the old implementation prior to 3.3, narrow and wide builds were supported regardless of the size of wchar_t. For a narrow build, if wchar_t was 32-bit, then PyUnico

[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-25 Thread Christopher Barker
IIRC, there were two builds- 16 and 32 bit Unicode. But it wasn’t UTF16, it was UCS-2. -CHB On Wed, May 25, 2022 at 11:32 AM Barry Scott wrote: > > > > On 25 May 2022, at 10:16, Stephen J. Turnbull < > stephenjturnb...@gmail.com> wrote: > > > > This is much > > better than the pre-PEP-393 sit

[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-25 Thread Barry Scott
> On 25 May 2022, at 10:16, Stephen J. Turnbull > wrote: > > This is much > better than the pre-PEP-393 situation (where the unicode type was > UTF-16, Only on Windows right? mac and Linux did not do this, at least with the bullds I have used for python 2.7. Barry ___

[Python-ideas] Re: TextIOBase: Make tell() and seek() pythonic

2022-05-24 Thread Chris Angelico
On Tue, 24 May 2022 at 23:03, wrote: > > seek() and tell() works with opaque values, called cookies. > This is close to low level details, but it is not pythonic. > (Non-pythonic and non-portable behaviour) > Currently feeding seek() with wrong values could lead to unexpected behaviour. > There sh