[Python-ideas] Re: Add function for reading a specific number of bytes/characters from a file object that fails noisily

2022-03-03 Thread Christopher Barker
On Thu, Mar 3, 2022 at 9:58 AM Kevin Mills wrote: > I actually initially was going to suggest a `strict` flag get added, but I > figured that would be impractical. I was mostly concerned about classes > that mimic file objects, because (obviously) their read methods wouldn't > include a `strict`

[Python-ideas] Re: Add function for reading a specific number of bytes/characters from a file object that fails noisily

2022-03-03 Thread Lincoln Auster
+0.1? > The code I'm currently working on involves parsing binary data. If I > ask for, say, 4 bytes, it's because I actually need 4 bytes and if the > file doesn't have 4 bytes for me, it's malformed. Because `f.read(4)` > can silently return less than 4 bytes and I don't want to have to >

[Python-ideas] Re: Add function for reading a specific number of bytes/characters from a file object that fails noisily

2022-03-03 Thread Kevin Mills
I actually initially was going to suggest a `strict` flag get added, but I figured that would be impractical. I was mostly concerned about classes that mimic file objects, because (obviously) their read methods wouldn't include a `strict` flag and you couldn't pass such objects to functions

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-03 Thread Chris Angelico
On Fri, 4 Mar 2022 at 02:48, Steven D'Aprano wrote: > > On Thu, Mar 03, 2022 at 10:30:32PM +1100, Chris Angelico wrote: > > On Thu, 3 Mar 2022 at 21:14, Steven D'Aprano wrote: > > > What did I say that made you think I denied the existence of filtered > > > iteration? Was it the post where I

[Python-ideas] Re: Add function for reading a specific number of bytes/characters from a file object that fails noisily

2022-03-03 Thread Christopher Barker
Rather than a new function, maybe a flag? read(n, strict=True) (Not sure if a block flag would also be useful, but maybe) -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython,

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-03 Thread Steven D'Aprano
On Thu, Mar 03, 2022 at 10:30:32PM +1100, Chris Angelico wrote: > On Thu, 3 Mar 2022 at 21:14, Steven D'Aprano wrote: > > What did I say that made you think I denied the existence of filtered > > iteration? Was it the post where I pointed out we've been able to do > > filtered iteration going

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-03 Thread Steven D'Aprano
What I said: "Python, for good or ill, is an opinionated language regarding indentation and statements." And then Greg refuted something I never said: > So if Python is opinionated about line lengths, it's rather > selectively opinionated. The Python language isn't opinionated about line

[Python-ideas] Re: Add function for reading a specific number of bytes/characters from a file object that fails noisily

2022-03-03 Thread Chris Angelico
On Thu, 3 Mar 2022 at 20:28, Steven D'Aprano wrote: > > On Thu, Mar 03, 2022 at 08:27:50AM -, Kevin Mills wrote: > > > The code I'm currently working on involves parsing binary data. If I > > ask for, say, 4 bytes, it's because I actually need 4 bytes and if the > > file doesn't have 4 bytes

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-03 Thread Chris Angelico
On Thu, 3 Mar 2022 at 21:14, Steven D'Aprano wrote: > What did I say that made you think I denied the existence of filtered > iteration? Was it the post where I pointed out we've been able to do > filtered iteration going back to Python 1.x days? ANYTHING can be done by composing concepts. We

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-03 Thread Greg Ewing
On 3/03/22 9:50 pm, Steven D'Aprano wrote: While you can put the block on the same line as the colon using semicolons: if condition: print(1); print(2) # Legal. and there's nothing to stop you from making arbitrarily long lines using this feature... if condition: print(1);

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-03 Thread Steven D'Aprano
On Thu, Mar 03, 2022 at 08:04:57PM +1100, Chris Angelico wrote: > Python has a history of making conceptual actions shorter than the > mere combination of their parts. For instance, we don't have this > construct: > > for i in range(len(stuff)) using thing = stuff[i]: Rather than inventing new

[Python-ideas] Re: Add function for reading a specific number of bytes/characters from a file object that fails noisily

2022-03-03 Thread Steven D'Aprano
On Thu, Mar 03, 2022 at 08:27:50AM -, Kevin Mills wrote: > The code I'm currently working on involves parsing binary data. If I > ask for, say, 4 bytes, it's because I actually need 4 bytes and if the > file doesn't have 4 bytes for me, it's malformed. Because `f.read(4)` > can silently

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-03 Thread Chris Angelico
On Thu, 3 Mar 2022 at 19:54, Steven D'Aprano wrote: > > On Thu, Mar 03, 2022 at 02:32:25AM +, Rob Cliffe via Python-ideas wrote: > > > But the proposal would give people the choice of > > Saving a level of indentation at the cost of having two > > suite-introductions on the same line. > >

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-03 Thread Steven D'Aprano
On Thu, Mar 03, 2022 at 02:32:25AM +, Rob Cliffe via Python-ideas wrote: > But the proposal would give people the choice of >     Saving a level of indentation at the cost of having two > suite-introductions on the same line. >     Keeping the two suit-introductions on separate lines (as

[Python-ideas] Add function for reading a specific number of bytes/characters from a file object that fails noisily

2022-03-03 Thread Kevin Mills
The code I'm currently working on involves parsing binary data. If I ask for, say, 4 bytes, it's because I actually need 4 bytes and if the file doesn't have 4 bytes for me, it's malformed. Because `f.read(4)` can silently return less than 4 bytes and I don't want to have to explicitly double