RE: list() coercion

Discussion in 'Python' started by Bob Gailer, Jul 17, 2003.

  1. Bob Gailer

    Bob Gailer Guest

    At 10:42 AM 7/17/2003 +1000, Delaney, Timothy C (Timothy) wrote:

    > > From: Ian Bicking [mailto:]
    > >
    > > Is there a way I can keep this from happening? Maybe something list()
    > > tries first that I can make fail. (I notice list() catches any
    > > exceptions in __len__ and then will just skip that step)

    >
    >Simplest thing is probably:
    >
    >ll = MyListLikeObject()
    >li = iter(ll)
    >l = list(li)
    >
    >i.e. explicitly create an iterator (which doesn't have a __len__) and
    >create the list from that.
    >
    >OTOH, if the problem is that creating the iterator is causing the problem
    >(calling __len__), you may need to create a proxy object that doesn't have
    >a __len__ and call list() on that.


    I have just read the docs 2.2.5 Iterator Types. Unfortunately this page
    seems to be written for someone who already understands the page. Is there
    any other explanation or examples?

    Bob Gailer

    303 442 2625


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003
     
    Bob Gailer, Jul 17, 2003
    #1
    1. Advertising

  2. [Bob Gailer]
    > I have just read the docs 2.2.5 Iterator Types. Unfortunately this page
    > seems to be written for someone who already understands the page. Is there
    > any other explanation or examples?


    The Py2.3 release candidate goes out tonight.
    In it, I've included sections on iterators and generators
    in the tutorial. I'm interested to know whether you
    find it helpful:

    http://www.python.org/dev/doc/devel/tut/node11.html#SECTION001190000000000000000
    0


    Raymond Hettinger
     
    Raymond Hettinger, Jul 17, 2003
    #2
    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. Harald Kirsch

    jython type coercion to interface type

    Harald Kirsch, Jun 25, 2003, in forum: Python
    Replies:
    1
    Views:
    1,725
    Harald Kirsch
    Jun 26, 2003
  2. Ian Bicking

    list() coercion

    Ian Bicking, Jul 17, 2003, in forum: Python
    Replies:
    5
    Views:
    364
    Ian Bicking
    Jul 18, 2003
  3. Holger Joukl

    python 2 coercion

    Holger Joukl, Aug 31, 2004, in forum: Python
    Replies:
    0
    Views:
    387
    Holger Joukl
    Aug 31, 2004
  4. Neil Schemenauer

    PEP: Generalised String Coercion

    Neil Schemenauer, Aug 6, 2005, in forum: Python
    Replies:
    1
    Views:
    294
  5. Replies:
    1
    Views:
    258
Loading...

Share This Page