On Sep 1, 5:31 pm, Philipp Hagemeister wrote:
> Mark Dickinson wrote:
> > (...) If you want to be
> > able to interpret instances of X as integers in the various Python
> > contexts that expect integers (e.g., hex(), but also things like list
> > indexing), you should implement the __index__ metho
Mark Dickinson wrote:
> (...) If you want to be
> able to interpret instances of X as integers in the various Python
> contexts that expect integers (e.g., hex(), but also things like list
> indexing), you should implement the __index__ method:
Thanks. Somehow forgot this magic method and deleted i
On Tue, Sep 1, 2009 at 8:22 AM, Philipp Hagemeister wrote:
> class X(object):
>def __int__(self): return 42
>def __hex__(self): return '2b' #sic
>
> hex(X())
>
>
> What would you expect? Python2 returns '2b', but python 3(74624) throws
> TypeError: 'X' object cannot be interpreted as an in
On Sep 1, 4:22 pm, Philipp Hagemeister wrote:
> class X(object):
> def __int__(self): return 42
> def __hex__(self): return '2b' #sic
>
> hex(X())
>
> What would you expect? Python2 returns '2b', but python 3(74624) throws
> TypeError: 'X' object cannot be interpreted as an integer. Why do
class X(object):
def __int__(self): return 42
def __hex__(self): return '2b' #sic
hex(X())
What would you expect? Python2 returns '2b', but python 3(74624) throws
TypeError: 'X' object cannot be interpreted as an integer. Why doesn't
python convert the object to int before constructing t