__future__ and __rdiv__

M

Massimo Di Pierro

Hello everybody,

I hope somebody could help me with this problem. If this is not the right place to ask, please direct me to the right place and apologies.
I am using Python 2.7 and I am writing some code I want to work on 3.x as well. The problem can be reproduced with this code:

# from __future__ import division
class Number(object):
def __init__(self,number):
self.number=number
def __rdiv__(self,other):
return other/self.number
print 10/Number(5)

It prints 2 as I expect. But if I uncomment the first line, I get:

Traceback (most recent call last):
File "test.py", line 8, in <module>
print 10/Number(5)
TypeError: unsupported operand type(s) for /: 'int' and 'Number'

Is this a bug or the __future__ division in 3.x changed the way operators are overloaded? Where can I read more?

Massimo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top