Re: Weird Indentation? (Or: is there a for...else construct?)
2009/2/7 andrew cooke and...@acooke.org: there's a justification for this awful mess here - http://mail.python.org/pipermail/python-3000/2006-March/000104.html i didn't know about this, and even after reading steven's broken (i assume) example, managed to get it backwards. What's awful about it? Except in the sense of inspiring awe, of course. No, Steven's example isn't broken, it works as the epydoc authors intended. (it's still in 3). Good. -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Indentation? (Or: is there a for...else construct?)
On Feb 7, 6:34 am, Andreas Waldenburger geekm...@usenot.de wrote: On Sun, 08 Feb 2009 01:28:00 +1100 Steven D'Aprano st...@pearwood.info wrote: Andreas Waldenburger wrote: It seems that there is a for...else construct. Replacing the inner if with pass seems to confirm this. The else clause is still executed. Yes, there is a for...else construct. That's something. In 6+ years of Python programming I've never seen or heard of this thing. This might be useful, apparently. yeah, about 4 years for me and i've never noticed this feature. [snip] What's broken here: Python or my brain? Perhaps we should not answer that question. I did phrase that rather provocatively, didn't I? Well thanks. I'll try to learn less noisily in the future. :) /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Weird Indentation? (Or: is there a for...else construct?)
I've found something in the spirit of the following (in the epydoc sources, if you care): if True: print outer if for t in range(2): if True: print for if else: print phantom else For the life of me I can't place the else. Which if clause does it belong to? None, it would seem from running the above snippet: outer if For if For if Phantom else It seems that there is a for...else construct. Replacing the inner if with pass seems to confirm this. The else clause is still executed. What's broken here: Python or my brain? /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Indentation? (Or: is there a for...else construct?)
On Sat, 7 Feb 2009 15:21:22 +0100 Andreas Waldenburger geekm...@usenot.de wrote: outer if For if For if Phantom else Geez, I'm a moron. This is obviously not the output from the snippet. But if you fix the capitalization, it is. Sorry for that. /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Indentation? (Or: is there a for...else construct?)
Andreas Waldenburger wrote: It seems that there is a for...else construct. Replacing the inner if with pass seems to confirm this. The else clause is still executed. Yes, there is a for...else construct. The else block runs if the for loop exits *without* a break. for i in range(20): if i == 10: break else: print no break here for i in range(20): if i == 100: break else: print no break here What's broken here: Python or my brain? Perhaps we should not answer that question. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Indentation? (Or: is there a for...else construct?)
Andreas Waldenburger wrote: I've found something in the spirit of the following (in the epydoc sources, if you care): if True: print outer if for t in range(2): if True: print for if else: print phantom else For the life of me I can't place the else. Which if clause does it belong to? None, it would seem from running the above snippet: outer if For if For if Phantom else It seems that there is a for...else construct. Replacing the inner if with pass seems to confirm this. The else clause is still executed. What's broken here: Python or my brain? Your rtfm sensor? http://docs.python.org/reference/compound_stmts.html#the-for-statement In short, the else suite is executed unless the for-loop is left via 'break': for i in [1]: ... break ... else: ... print else ... for i in [1]: ... pass ... else: ... print else ... else Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Indentation? (Or: is there a for...else construct?)
On Sun, 08 Feb 2009 01:28:00 +1100 Steven D'Aprano st...@pearwood.info wrote: Andreas Waldenburger wrote: It seems that there is a for...else construct. Replacing the inner if with pass seems to confirm this. The else clause is still executed. Yes, there is a for...else construct. That's something. In 6+ years of Python programming I've never seen or heard of this thing. This might be useful, apparently. [snip] What's broken here: Python or my brain? Perhaps we should not answer that question. I did phrase that rather provocatively, didn't I? Well thanks. I'll try to learn less noisily in the future. :) /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Indentation? (Or: is there a for...else construct?)
Andreas Waldenburger wrote: On Sun, 08 Feb 2009 01:28:00 +1100 Steven D'Aprano st...@pearwood.info wrote: Andreas Waldenburger wrote: It seems that there is a for...else construct. Replacing the inner if with pass seems to confirm this. The else clause is still executed. Yes, there is a for...else construct. That's something. In 6+ years of Python programming I've never seen or heard of this thing. This might be useful, apparently. One use case is: for x in list_of_items: if x.value == desired_value: desired_name = x.name break else: print Couldn't find %s % x.value [snip] What's broken here: Python or my brain? Perhaps we should not answer that question. I did phrase that rather provocatively, didn't I? Well thanks. I'll try to learn less noisily in the future. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Indentation? (Or: is there a for...else construct?)
Peter Otten schrieb: Andreas Waldenburger wrote: I've found something in the spirit of the following (in the epydoc sources, if you care): if True: print outer if for t in range(2): if True: print for if else: print phantom else For the life of me I can't place the else. Which if clause does it belong to? None, it would seem from running the above snippet: outer if For if For if Phantom else It seems that there is a for...else construct. Replacing the inner if with pass seems to confirm this. The else clause is still executed. What's broken here: Python or my brain? Your rtfm sensor? http://docs.python.org/reference/compound_stmts.html#the-for-statement In short, the else suite is executed unless the for-loop is left via 'break': Or exceptions of course. Might be obvious, but for completeness' sake. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Indentation? (Or: is there a for...else construct?)
there's a justification for this awful mess here - http://mail.python.org/pipermail/python-3000/2006-March/000104.html i didn't know about this, and even after reading steven's broken (i assume) example, managed to get it backwards. the else is if there *isn't* a break and is for search loops (see link above). (it's still in 3). andrew Steven D'Aprano wrote: Andreas Waldenburger wrote: It seems that there is a for...else construct. Replacing the inner if with pass seems to confirm this. The else clause is still executed. Yes, there is a for...else construct. The else block runs if the for loop exits *without* a break. for i in range(20): if i == 10: break else: print no break here for i in range(20): if i == 100: break else: print no break here What's broken here: Python or my brain? Perhaps we should not answer that question. -- Steven -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list