On 09/15/2014 07:44 AM, Steven D'Aprano wrote:
On Mon, Sep 15, 2014 at 07:24:17AM -0700, Ethan Furman wrote:
In Python 2, hex() calls the dunder method __hex__. That has been removed in Python 3. Does anyone know why?
__hex__ and __oct__ were removed in favor of __index__. __index__ returns the number as an integer (if possible to do so without conversion from, say, float or complex or ...). __hex__ and __oct__ did the same, and were redundant.
No, __hex__ returned a string. It could be used to implement (say) a floating point hex representation, or hex() of bytes.
Right, sorry. I had the wrong return type in mind. Now you have to use the hex format codes.
I don't suppose anyone would support bringing back __hex__?
I don't think we need another formatting operator. we already have % and .format() -- do we still have string templates?