[Chicago] Chicago Digest, Vol 123, Issue 6

Len Wanger len_wanger at hotmail.com
Tue Nov 10 10:51:39 EST 2015


Try changing your next routine to this:

def __next__(self):
      while True:
            if self.counter == len(self.array) - 1:
                  self.counter = -1
            self.counter+=1
            yield self.array[self.counter]
Len

> From: chicago-request at python.org
> Subject: Chicago Digest, Vol 123, Issue 6
> To: chicago at python.org
> Date: Tue, 10 Nov 2015 09:54:39 -0500
> 
> Send Chicago mailing list submissions to
> 	chicago at python.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	https://mail.python.org/mailman/listinfo/chicago
> or, via email, send a message with subject or body 'help' to
> 	chicago-request at python.org
> 
> You can reach the person managing the list at
> 	chicago-owner at python.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Chicago digest..."
> 
> 
> Today's Topics:
> 
>    1. Can this be done with a yield statement and generator object?
>       (Lewit, Douglas)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Tue, 10 Nov 2015 02:10:12 -0600
> From: "Lewit, Douglas" <d-lewit at neiu.edu>
> To: The Chicago Python Users Group <chicago at python.org>
> Subject: [Chicago] Can this be done with a yield statement and
> 	generator object?
> Message-ID:
> 	<CAPdZZGxoZRe=L7LyVQ30QBaqy_NeRWrisOdraQpcu-wFXEhqAw at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> Hey guys,
> 
> I'm attaching a simple class that I created in Python.... Python 3 to be
> specific, but I think it should work in Python 2 as well, maybe.  Anyhow,
> is there a way to implement the same concept using a *yield statement* in a
> function to create a generator object?  Just wondering.  Let me know,
> thanks!
> 
> Best,
> 
> Douglas Lewit
> 
> P.S.  Obviously if you use a generator object to do this then the generator
> object would never produce the StopIteration error.  But I'm kind of
> confused about how to create and define a generator object that would
> produce this cyclical behavior in an array or list.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/chicago/attachments/20151110/b012ba59/attachment.html>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: Circular_List_in_Python.png
> Type: image/png
> Size: 277517 bytes
> Desc: not available
> URL: <http://mail.python.org/pipermail/chicago/attachments/20151110/b012ba59/attachment.png>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: CircularList.py
> Type: text/x-python
> Size: 373 bytes
> Desc: not available
> URL: <http://mail.python.org/pipermail/chicago/attachments/20151110/b012ba59/attachment.py>
> 
> ------------------------------
> 
> Subject: Digest Footer
> 
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
> 
> 
> ------------------------------
> 
> End of Chicago Digest, Vol 123, Issue 6
> ***************************************
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20151110/685b207b/attachment.html>


More information about the Chicago mailing list