Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Supporting list()

Reply
Thread Tools

Re: Supporting list()

 
 
Dave Angel
Guest
Posts: n/a
 
      12-17-2012
On 12/17/2012 09:33 AM, Skip Montanaro wrote:
> What method(s) does a class have to support to properly emulate a container
> which supports turning it into a list? For example:
>
> class Foo:
> pass
>
> f = Foo()
> print list(f)
>
> Is it just __iter__() and next()? (I'm still using 2.4 and 2.7.)


I believe the container class needs to define the __iter__() method,
which has to return an iterator object.

That (possibly different) iterator class needs both an __iter__() method
and a next() method.

If the container class is also the iterator class, which is common, then
you just need one __iter__() method, which returns self.



--

DaveA

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wireless Bridge Supporting PEAP-MSCHAPv2 Ernie Wireless Networking 0 09-29-2005 05:42 PM
Sample for supporting file attachements Ryan ASP .Net 4 12-21-2004 06:37 PM
Any Active-X object supporting Drag and drop upload? Eilsa ASP .Net 0 11-23-2004 02:32 AM
Firewall supporting MIDCOM or any API for management Josip Gracin Cisco 0 10-06-2004 08:12 AM
Re: How to debug supporting classes in ASP.Net project Davide Vernole [MVP] ASP .Net 0 09-03-2004 04:39 PM



Advertisments