[Python-ideas] Re: Add "elif" to "for_stmt" and "while_stmt"

2019-12-15 Thread Andrey KomIssarov
This change does not carry changes in the logic, only syntactic optimization. Actually how it should work Now the logic is written like this: (Code 1) for i in range (j): ... else: if i> 5: ... The idea is to shorten it to a record like this: (Code 2) for i in range (j): ... e

[Python-ideas] Re: Add "elif" to "for_stmt" and "while_stmt"

2019-12-15 Thread Serhiy Storchaka
14.12.19 23:37, komissar.off.and...@gmail.com пише: Hello! I think it will be useful in Python syntax if we can use "elif" in "for" and "while" statements besides "else" Example for i in range(j): ... elif i > 5: ... else: ... What you think about this change? I sometimes with

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread Oscar Benjamin
On Sun, 15 Dec 2019 at 05:54, David Mertz wrote: > > A pattern I've written a number of times is roughly: > > lines = open(fname) > header = next(lines) > for line in lines: > process (line, header) > > That's not so artificial, I think. Of course, first() would also work here. > But I'm not

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread Serhiy Storchaka
13.12.19 12:45, Steven D'Aprano пише: On Fri, Dec 13, 2019 at 09:24:20AM +0200, Serhiy Storchaka wrote: 12.12.19 03:22, Stephen J. Turnbull пише: I would prefer that it not be implemented at all, but if it is implemented, its behavior should respect the intuition of the majority of those who wa

[Python-ideas] Re: Add "elif" to "for_stmt" and "while_stmt"

2019-12-15 Thread Anders Hovmöller
In my opinion this doesn't make sense. For else is already unreadable and confusing so adding to it would be more so. > On 15 Dec 2019, at 00:16, komissar.off.and...@gmail.com wrote: > > Hello! > I think it will be useful in Python syntax if we can use "elif" in "for" and > "while" statements

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread David Mertz
Yes, of course. I was just trying to illustrate using next() in a non-artificial way. In real code (but truthfully, probably not in my quick "one off" scripts) I write lines = get_lines_file_or_elswhere(resource) header = next(lines, sentinel) if looks_like_header(header): for line in lines:

[Python-ideas] Re: Add "elif" to "for_stmt" and "while_stmt"

2019-12-15 Thread Siddharth Prajosh
I don't think this is really useful. For else in itself is a very odd thing to have. For-elif-else will make this even more complicated. But that's just my opinion. Cheers, Siddharth Prajosh On Sun, 15 Dec, 2019, 19:28 Anders Hovmöller, wrote: > In my opinion this doesn't make sense. For else i

[Python-ideas] Re: Add "elif" to "for_stmt" and "while_stmt"

2019-12-15 Thread Andrew Barnert via Python-ideas
On Dec 15, 2019, at 02:08, Andrey KomIssarov wrote: > > As for the real cases where it will be applicable, I have already found > several in our project > For example, here in Tools/importbench/importbench.py > > while total_time try: > total_time + = timer.timeit (1) > finall

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread Christopher Barker
On Sun, Dec 15, 2019 at 6:40 AM David Mertz wrote: > Yes, of course. I was just trying to illustrate using next() in a > non-artificial way. In real code (but truthfully, probably not in my quick > "one off" scripts) I write > > lines = get_lines_file_or_elswhere(resource) > header = next(lines,

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread Eric V. Smith
On 12/15/2019 2:21 PM, Christopher Barker wrote: On Sun, Dec 15, 2019 at 6:40 AM David Mertz > wrote: Yes, of course. I was just trying to illustrate using next() in a non-artificial way. In real code (but truthfully, probably not in my quick "one off" scripts

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread Andrew Barnert via Python-ideas
On Dec 14, 2019, at 21:52, David Mertz wrote: > > A pattern I've written a number of times is roughly: > > lines = open(fname) > header = next(lines) > for line in lines: > process (line, header) > > That's not so artificial, I think. Of course, first() would also work here. > But I'm not

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread David Mertz
On Sun, Dec 15, 2019, 2:21 PM Christopher Barker wrote: > On Sun, Dec 15, 2019 at 6:40 AM David Mertz wrote: > >> lines = get_lines_file_or_elswhere(resource) >> header = next(lines, sentinel) >> if looks_like_header(header): >> for line in lines: >> ... >> > > Hmm, interesting -- so

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread Tim Peters
[Christopher Barker ] > ... > BTW: this has been a REALLY LONG thread -- I think it's time for a > concrete proposal to be written up, sonce it appears we're not all > clear on what we're talking about. For my part I think a first() function > would be nice, an am open to a couple variations, so so

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread Christopher Barker
On Sun, Dec 15, 2019 at 11:45 AM David Mertz wrote: > Hmm, interesting -- so this means that you do write code expecting a >> generic iterator, rather than a file-like object. >> > > How file-like do you need? I've certainly written things that usually take > an actual file, but sometimes get io.

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread Christopher Barker
On Sun, Dec 15, 2019 at 12:08 PM Tim Peters wrote: > > Tim: what version do you have in mind? > > Same as always: exactly what more-itertools has supplied for years > already :-) > > If the iterable is empty/exhausted, by default ValueError is raised, > but that can be overridden by also passing