Re: A use-case for for...else with no break

2017-11-03 Thread Steve D'Aprano
On Fri, 3 Nov 2017 09:13 pm, Serhiy Storchaka wrote: > What the interpreter or configuration do you use? The standard > interpreter uses '>>> ' as a prompt. I have this in my Python startup file: if (sys.version_info[0] >= 3 and os.name == 'posix' and os.environ['TERM'] in ['xterm', 'vt1

Re: A use-case for for...else with no break

2017-11-03 Thread Serhiy Storchaka
02.11.17 12:10, Steve D'Aprano пише: Occasionally it is useful to loop over a bunch of stuff in the interactive interpreter, printing them as you go on a single line: for x in something(): print(x, end='') If you do that, the prompt overwrites your output, and you get a mess: py> for x i

Re: A use-case for for...else with no break

2017-11-03 Thread Steve D'Aprano
On Fri, 3 Nov 2017 04:22 pm, Paul Rubin wrote: > Steve D'Aprano writes: >> for x in something(): >> print(x, end='') > > print(''.join(something())) I hoped that people would recognise a simplified, toy example used only to illustrate a technique, rather than an exact copy and paste of som

Re: A use-case for for...else with no break

2017-11-02 Thread Paul Rubin
Steve D'Aprano writes: > for x in something(): > print(x, end='') print(''.join(something())) -- https://mail.python.org/mailman/listinfo/python-list

Re: A use-case for for...else with no break

2017-11-02 Thread Terry Reedy
On 11/2/2017 8:53 PM, Steve D'Aprano wrote: On Fri, 3 Nov 2017 09:20 am, Terry Reedy wrote: This seems like a bug in how Python interacts with your console. On Windows, in Python started from an icon or in Command Prompt: >>> for c in 'abc': print(c, end='') ... abc>>> That's still unfortu

Re: A use-case for for...else with no break

2017-11-02 Thread Steve D'Aprano
On Fri, 3 Nov 2017 09:20 am, Terry Reedy wrote: > This seems like a bug in how Python interacts with your console. On > Windows, in Python started from an icon or in Command Prompt: > > >>> for c in 'abc': print(c, end='') > ... > abc>>> That's still unfortunate: the prompt is immediately afte

Re: A use-case for for...else with no break

2017-11-02 Thread Terry Reedy
On 11/2/2017 6:10 AM, Steve D'Aprano wrote: Occasionally it is useful to loop over a bunch of stuff in the interactive interpreter, printing them as you go on a single line: for x in something(): print(x, end='') If you do that, the prompt overwrites your output, and you get a mess: py>

Re: A use-case for for...else with no break

2017-11-02 Thread Steve D'Aprano
On Thu, 2 Nov 2017 10:45 pm, Alberto Berti wrote: >> "Steve" == Steve D'Aprano writes: > > py> for x in "abcdefgh": > Steve> ... print(x, end='') > Steve> ... > py> efghpy> > > > Steve> "For ... else" to the rescue! > > py> for char in "abcdefgh": > Steve>

Re: A use-case for for...else with no break

2017-11-02 Thread Alberto Berti
> "Wolfgang" == Wolfgang Maier > writes: Wolfgang> Try running it interactively and you'll see, Wolfgang> wolfgang I've tried but my muscolar memory failed me... i've issued a C-c C-c that usually would have sent the region of text to the interpreter session (when done from python

Re: A use-case for for...else with no break

2017-11-02 Thread Wolfgang Maier
On 11/02/2017 12:45 PM, Alberto Berti wrote: "Steve" == Steve D'Aprano writes: py> for x in "abcdefgh": Steve> ... print(x, end='') Steve> ... py> efghpy> Steve> "For ... else" to the rescue! py> for char in "abcdefgh": Steve> ... print(char, end='

Re: A use-case for for...else with no break

2017-11-02 Thread Alberto Berti
> "Steve" == Steve D'Aprano writes: py> for x in "abcdefgh": Steve> ... print(x, end='') Steve> ... py> efghpy> Steve> "For ... else" to the rescue! py> for char in "abcdefgh": Steve> ... print(char, end='') Steve> ... else: Steve> ... print(