On 9/12/2011 12:55 PM, Ian Kelly wrote:
On Sun, Sep 11, 2011 at 6:45 PM, Terry Reedy wrote:
whereas, you are right, it breaks it noisily in the body. So Ian's claim
that StopIteration must be caught to avoid silent termination is not true.
Thanks for pointing out what I saw but did not cognize
On 9/12/2011 9:06 AM, Duncan Booth wrote:
Terry Reedy wrote:
The statement containing the explicit next(items) call can optionally be
wrapped to explicitly handle the case of an empty iterable in whatever
manner is desired.
try:
except StopIteration:
raise ValueError("iterable ca
On Mon, Sep 12, 2011 at 10:55 AM, Ian Kelly wrote:
> But you can't write the function under the assumption that it will
> only be called from the function body. The following is a slight
> reorganization of your example that does exhibit the problem:
s/function body/for-loop body/
--
http://mai
On Sun, Sep 11, 2011 at 6:45 PM, Terry Reedy wrote:
> whereas, you are right, it breaks it noisily in the body. So Ian's claim
> that StopIteration must be caught to avoid silent termination is not true.
> Thanks for pointing out what I saw but did not cognize the full implication
> of before. A b
Terry Reedy wrote:
> The statement containing the explicit next(items) call can optionally be
> wrapped to explicitly handle the case of an empty iterable in whatever
> manner is desired.
>
> try:
>
> except StopIteration:
> raise ValueError("iterable cannot be empty")
>
>
Alterna
On 9/11/2011 6:41 PM, Chris Angelico wrote:
On Mon, Sep 12, 2011 at 2:47 AM, Terry Reedy wrote:
What you are saying is a) that the following code
for title in ['amazinG', 'a helL of a fiGHT', '', 'igNordEd']:
print(fix_title(title))
At least in Python 3.2, this isn't the case. StopItera
On Mon, Sep 12, 2011 at 2:47 AM, Terry Reedy wrote:
> What you are saying is a) that the following code
>
> for title in ['amazinG', 'a helL of a fiGHT', '', 'igNordEd']:
> print(fix_title(title))
>
At least in Python 3.2, this isn't the case. StopIteration breaks the
loop only if it's raised
Terry Reedy wrote:
On 9/11/2011 12:01 AM, Ian Kelly wrote:
On Sat, Sep 10, 2011 at 1:36 PM, Terry Reedy wrote:
The statement containing the explicit next(items) call can optionally be
wrapped to explicitly handle the case of an empty iterable in whatever
manner is desired.
try:
except St
On 9/11/2011 9:41 AM, Peter Otten wrote:
Terry Reedy wrote:
3. Process the items of an iterable in pairs.
items = iter(iterable)
for first in items:
second = next(items)
This time, StopIteration is raised for an odd number of items. Catch and
process as desired. One possibility i
On 9/11/2011 12:01 AM, Ian Kelly wrote:
On Sat, Sep 10, 2011 at 1:36 PM, Terry Reedy wrote:
The statement containing the explicit next(items) call can optionally be
wrapped to explicitly handle the case of an empty iterable in whatever
manner is desired.
try:
except StopIteration:
rai
Terry Reedy wrote:
> 3. Process the items of an iterable in pairs.
>
> items = iter(iterable)
> for first in items:
> second = next(items)
>
>
> This time, StopIteration is raised for an odd number of items. Catch and
> process as desired. One possibility is to raise ValueError("Iter
On 09/10/11 14:36, Terry Reedy wrote:
1. Process first item of an iterable separately.
A traditional solution is a flag variable that is tested for each item.
first = True
for item in iterable:
if first:
first = False
else:
(I have seen code like this posted on thi
On Sat, Sep 10, 2011 at 1:36 PM, Terry Reedy wrote:
> The statement containing the explicit next(items) call can optionally be
> wrapped to explicitly handle the case of an empty iterable in whatever
> manner is desired.
>
> try:
>
> except StopIteration:
> raise ValueError("iterable cannot
Python's iterator protocol for an iterator 'items' allows combinations
of explicit "next(items)" calls with the implicit calls of a "for item
in items:" loop. There are at least three situations in which this can
be useful. (While the code posted here is not testable, being incomplete
or having
14 matches
Mail list logo