[DiscordArchive] what do you mean by do until exception?
[DiscordArchive] what do you mean by do until exception?
Archived author: Skarn • Posted: 2018-02-11T11:11:27.410000+00:00
Original source
But I am not sure
Archived author: Amaroth • Posted: 2018-02-11T11:11:29.237000+00:00
Original source
```
it = iter(sequence)
while True:
try:
value = it.next()
except StopIteration:
break
print(value)
```
Archived author: Skarn • Posted: 2018-02-11T11:12:32.505000+00:00
Original source
ah, yes, you are right
Archived author: Skarn • Posted: 2018-02-11T11:12:45.585000+00:00
Original source
that is indeed called by generator objects
Archived author: Skarn • Posted: 2018-02-11T11:13:00.327000+00:00
Original source
don't get me wrong though, you don't have to do that shit every time you make a for loop.
Archived author: Amaroth • Posted: 2018-02-11T11:13:01.292000+00:00
Original source
Its weird design. There is probably some reason for that though
Archived author: Skarn • Posted: 2018-02-11T11:13:35.854000+00:00
Original source
Yes, python ideology. The concept is that it is better ask for forgiveness (catch an exception) than ask for permission
Archived author: Skarn • Posted: 2018-02-11T11:14:34.448000+00:00
Original source
but you can really only face those exceptions yourself, if you do async programming with generator objects
Archived author: Skarn • Posted: 2018-02-11T11:14:45.723000+00:00
Original source
usual for loop handles that by itself
Archived author: Amaroth • Posted: 2018-02-11T11:20:38.880000+00:00
Original source
Yep, but I personally don't call an end of collection being exceptional occurence