[Python-Dev] Xrange and Slices

Patrick K. O'Brien pobrien@orbtech.com
Wed, 26 Jun 2002 08:49:26 -0500


[Oren Tirosh]
>
> Two strange things about xrange objects:
> >>> xrange(1,100,2)
> xrange(1, 101, 2)
>
> It's been there since at least Python 2.0.  Hasn't anyone noticed this
> bug before?
>
> >>> dir(x)
> []
> Shouldn't it have at least __class__, __repr__, etc and everything else
> that object has?

What is x in your example? Assuming x == xrange, I get this with Python
2.2.1:

>>> dir(xrange)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__name__', '__new__',
'__reduce__', '__repr__', '__self__', '__setattr__', '__str__']

Assuming x == xrange(1, 100, 2):

>>> x = xrange(1, 100, 2)
>>> dir(x)
PyCrust-Shell:1: DeprecationWarning: xrange object's 'start', 'stop' and
'step' attributes are deprecated
['start', 'step', 'stop', 'tolist']

--
Patrick K. O'Brien
Orbtech
-----------------------------------------------
"Your source for Python software development."
-----------------------------------------------
Web:  http://www.orbtech.com/web/pobrien/
Blog: http://www.orbtech.com/blog/pobrien/
Wiki: http://www.orbtech.com/wiki/PatrickOBrien
-----------------------------------------------