Issue 6762: strange string representation of xrange in print (original) (raw)

Created on 2009-08-22 19:12 by mintaka, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg91871 - (view) Author: Mintaka (mintaka) Date: 2009-08-22 19:12
String representation of xrange return keyword with value. foo = xrange(5) print foo >>> xrange(5) foo.__str__() >>> xrange(5) I think, that expected result should be somethink like this: >>> <xrange object at 0x00AFB970>
msg91872 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2009-08-22 19:47
For types where it's possible, the str or repr returns a string that can be passed to eval: >>> for i in eval(str(xrange(5))): ... print i ... 0 1 2 3 4 xrange (and list, and tuple, and others) fall into this category.
msg91875 - (view) Author: Mintaka (mintaka) Date: 2009-08-22 20:35
Thanks for clarification. I compared it with iter([0,1,2,3,4]).__str__() which behaviour seems to me closer then list or tuple.
msg91878 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-08-22 22:21
I concur with Eric. The eval(repr(obj)) should be made to work when possible. We do this with itertools.count() and other places where it makes sense.
History
Date User Action Args
2022-04-11 14:56:52 admin set github: 51011
2009-08-22 22:21:49 rhettinger set nosy: + rhettingermessages: +
2009-08-22 20:35:04 mintaka set messages: +
2009-08-22 19:48:00 eric.smith set status: open -> closednosy: + eric.smithmessages: + resolution: not a bugstage: resolved
2009-08-22 19:14:15 mintaka set type: behavior
2009-08-22 19:12:19 mintaka create