Looping [was Re: Python and the need for speed]
Marko Rauhamaa
marko at pacujo.net
Mon Apr 17 14:38:05 EDT 2017
Ben Bacarisse <ben.usenet at bsb.me.uk>:
> Marko Rauhamaa <marko at pacujo.net> writes:
>> What I notice in my numbers is that about one half of my while loops
>> are "while True", and about a third of my loops are while loops.
>
> I fo[u]nd the proportion on while True: loops surprising. Is there
> something about Python that encourages that kind of loop?
Here's a typical example of such a loop in Python (ver 2):
while True:
try:
snippet = os.read(rdfd, 1000)
except OSError as e:
if e.errno == errno.EAGAIN:
return
raise
if not snippet:
break
self.stdout_snippets.append(snippet)
I find myself writing similar loops in C a lot, as well.
Marko
More information about the Python-list
mailing list