Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > __future__ and __rdiv__

Reply
Thread Tools

__future__ and __rdiv__

 
 
Massimo Di Pierro
Guest
Posts: n/a
 
      01-23-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Funny behaviour with __future__ and doctest between 2.6 and 3.1 Mattsteel Python 4 01-30-2010 10:25 AM
timeit and __future__ Karl Chen Python 1 06-20-2009 01:39 PM
Re: __future__ and compile: unrecognised flags Steve Holden Python 1 12-14-2008 08:46 AM
__future__ and compile: unrecognised flags Poor Yorick Python 0 12-13-2008 11:29 AM
__future__ and unrecognised flags Poor Yorick Python 0 12-12-2008 09:52 PM



Advertisments