On Wed, 29 Feb 2012 10:24:18 +1100, Chris Angelico wrote:
> Every syntactic structure should
> have the addition of a "foo:" suite, which will run when the programmer
> expects it to and no other time. This would solve a LOT of problems.
Indeed, when I design my killer language, the identifie
On Wed, Feb 29, 2012 at 9:56 AM, Rick Johnson
wrote:
> On Feb 24, 8:54 am, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote:
>
>> In Python 4000, I think for loops should be spelled:
>>
>> for name in iterable:
>> # for block
>> then:
>> # only if not exited with break
>> else:
>>
On Feb 24, 8:54 am, Steven D'Aprano wrote:
> for...else is a very useful construct, but the name is misleading. It
> took me a long time to stop thinking that the else clause executes when
> the for loop was empty.
Agreed. This is a major stumbling block for neophytes.
> In Python 4000, I think
Steven D'Aprano wrote:
>> The code in the else suite executes only when the for loop is left via
>> break. A non-empty iterable is required but not sufficient.
>
> You have a typo there. As your examples show, the code in the else suite
> executes only when the for loop is NOT left via break (or
On 24 February 2012 14:54, Steven D'Aprano
wrote:
> for...else is a very useful construct, but the name is misleading. It
> took me a long time to stop thinking that the else clause executes when
> the for loop was empty.
This is why I think we should call this construct "for / break / else"
rat
On Fri, 24 Feb 2012 13:44:15 +0100, Peter Otten wrote:
for i in []:
> ... pass
> ... else:
> ... print "else"
> ...
> else
for i in [42]:
> ... pass
> ... else:
> ... print "else"
> ...
> else
for i in [42]:
> ... break
> ... else:
> ... print "else"
> ...
>>
Peter Otten wrote:
> The code in the else suite executes only when the for loop is left via
> break.
Oops, the following statement is nonsense:
> A non-empty iterable is required but not sufficient.
Let me try again:
A non-empty iterable is required but not sufficient to *skip* the else-suite
Rick Johnson wrote:
> On Feb 23, 6:30 pm, Alex Willmer wrote:
>> [...]
>> as a standard looping-with-index construct. In Python for loops don't
>> create a scope, so the loop variables are available afterward. I've
>> sometimes used this to print or return a record count e.g.
>>
>> for i, x in en
On Feb 23, 6:30 pm, Alex Willmer wrote:
> [...]
> as a standard looping-with-index construct. In Python for loops don't
> create a scope, so the loop variables are available afterward. I've
> sometimes used this to print or return a record count e.g.
>
> for i, x in enumerate(seq):
> # do stuff
Ethan Furman wrote:
> Steven D'Aprano wrote:
>> On Thu, 23 Feb 2012 16:30:09 -0800, Alex Willmer wrote:
>>
>>> This week I was slightly surprised by a behaviour that I've not
>>> considered before. I've long used
>>>
>>> for i, x in enumerate(seq):
>>># do stuff
>>>
>>> as a standard looping-
On 24/02/2012 03:49, Ethan Furman wrote:
Steven D'Aprano wrote:
On Thu, 23 Feb 2012 16:30:09 -0800, Alex Willmer wrote:
This week I was slightly surprised by a behaviour that I've not
considered before. I've long used
for i, x in enumerate(seq):
# do stuff
as a standard looping-with-index co
Steven D'Aprano wrote:
On Thu, 23 Feb 2012 16:30:09 -0800, Alex Willmer wrote:
This week I was slightly surprised by a behaviour that I've not
considered before. I've long used
for i, x in enumerate(seq):
# do stuff
as a standard looping-with-index construct. In Python for loops don't
crea
Alex Willmer writes:
> i = 0
> for x in seq:
> # do stuff
> i += 1
> print 'Processed %i records' % i
>
> Just thought it worth mentioning, curious to hear other options/
> improvements/corrections.
Stephen gave an alternate patch, but you are right, it is a pitfall that
can be easy to mi
On Thu, 23 Feb 2012 16:30:09 -0800, Alex Willmer wrote:
> This week I was slightly surprised by a behaviour that I've not
> considered before. I've long used
>
> for i, x in enumerate(seq):
># do stuff
>
> as a standard looping-with-index construct. In Python for loops don't
> create a scope
14 matches
Mail list logo