On 01/02/2013 11:41 AM, Steven D'Aprano wrote: > <snip> > > The bit about __index__ refers to using trunc(): > > "I still really wish I had followed Pascal's lead instead of C's here: > Pascal requires you to use trunc() to convert a real to an integer. ... > If we had done it that way, we wouldn't have had to introduce the > index() builtin and the corresponding infrastructure (__index__ > and a whole slew of C APIs)." > > > I don't know what this "index() builtin" is, it doesn't appear to exist. > But __index__ is a special method that converts to int without rounding > or truncating, intended only for types that emulate ints but not other > numeric types:
I suspect that at one time, an index() built-in was intended. It's now available as an operator, and simply calls the __index__() as you say. import operator print operator.index(myobject) works, at least in 2.7 and 3.x -- DaveA _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor