Supporting list()

Discussion in 'Python' started by Skip Montanaro, Dec 17, 2012.

  1. 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.)

    Thx,

    Skip
    Skip Montanaro, Dec 17, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lin Chat
    Replies:
    3
    Views:
    99
    Huw Collingbourne
    May 30, 2008
  2. Dave Angel

    Re: Supporting list()

    Dave Angel, Dec 17, 2012, in forum: Python
    Replies:
    0
    Views:
    142
    Dave Angel
    Dec 17, 2012
  3. Ethan Furman

    Re: Supporting list()

    Ethan Furman, Dec 17, 2012, in forum: Python
    Replies:
    0
    Views:
    178
    Ethan Furman
    Dec 17, 2012
  4. Skip Montanaro

    Re: Supporting list()

    Skip Montanaro, Dec 17, 2012, in forum: Python
    Replies:
    0
    Views:
    140
    Skip Montanaro
    Dec 17, 2012
  5. Ethan Furman

    Re: Supporting list()

    Ethan Furman, Dec 17, 2012, in forum: Python
    Replies:
    0
    Views:
    171
    Ethan Furman
    Dec 17, 2012
Loading...

Share This Page