Where do you use generators feature in your python code?

Posted by systempuntoout on Stack Overflow See other posts from Stack Overflow or by systempuntoout
Published on 2010-03-29T06:58:18Z Indexed on 2010/03/29 7:03 UTC
Read the original article Hit count: 488

Filed under:
|

I have studied generators feature and i think i got it but i would like to understand where i could apply it in my code.

I have in mind the following example i read in "Python essential reference" book:

# tail -f
 def tail(f):
  f.seek(0,2) 
  while True:
   line = f.readline() 
   if not line: 
     time.sleep(0.1)
     continue
   yield line

Do you have any other effective example where generators are the best tool for the job like tail -f?

How often do you use generators feature and in which kind of functionality\part of program do you usually apply it?

© Stack Overflow or respective owner

Related posts about python

Related posts about generators