[Python-Dev] _length_cue() (original) (raw)
Jack Diederich jack at performancedrivers.com
Thu Feb 9 17:21:49 CET 2006
- Previous message: [Python-Dev] _length_cue()
- Next message: [Python-Dev] _length_cue()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Raymond Hettinger]
[Armin Rigo] > BTW the reason I'm looking at this is that I'm considering adding > another undocumented internal-use-only method, maybe getitemcue(), > that would try to guess what the nth item to be returned will be. This > would allow the repr of some iterators to display more helpful > information when playing around with them at the prompt, e.g.: > >>>> enumerate([3.1, 3.14, 3.141, 3.1415, 3.14159, 3.141596]) > <enumerate (0, 3.1), (1, 3.14), (2, 3.141),... length 6>
At one point, I explored and then abandoned this idea. For objects like itertools.count(n), it worked fine -- the state was readily knowable and the eval(repr(obj)) round-trip was possible. However, for tools like enumerate(), it didn't make sense to have a preview that only applied in a tiny handful of (mostly academic) cases and was not evaluable in any case.
That is my experience too. Even for knowable sequences people consume it in series and not just one element. My permutation module supports pulling out just the Nth canonical permutation. Lots of people have used the module and no one uses that feature.
import probstat p = probstat.Permutation(range(4)) p[0] [0, 1, 2, 3] len(p) 24 p[23] [3, 2, 1, 0]
-jackdied
- Previous message: [Python-Dev] _length_cue()
- Next message: [Python-Dev] _length_cue()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]