Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'everybody,': 0.07; 'prints': 0.07; 'received:verizon.net': 0.07; 'terry': 0.07; 'python': 0.08; '__future__': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'am,': 0.12; 'def': 0.13; '2.7': 0.13; 'float': 0.13; '12:22': 0.16; 'massimo': 0.16; 'reedy': 0.16; 'wrote:': 0.16; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; 'division': 0.23; 'int,': 0.23; 'code': 0.25; 'skip:_ 20': 0.26; 'import': 0.27; 'somebody': 0.27; 'problem': 0.29; 'print': 0.29; 'class': 0.29; '3.x': 0.30; 'apologies.': 0.30; 'header:User- Agent:1': 0.33; 'to:addr:python-list': 0.33; 'rather': 0.34; 'header:X-Complaints-To:1': 0.34; 'problem.': 0.36; 'but': 0.37; 'received:org': 0.37; 'using': 0.37; 'skip:_ 10': 0.37; 'could': 0.37; 'some': 0.38; 'should': 0.38; '(with': 0.39; 'help': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'hope': 0.61; 'fact,': 0.63; 'believe': 0.65; 'direct': 0.66; 'reproduced': 0.84; 'ask,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: __future__ and __rdiv__ Date: Mon, 23 Jan 2012 03:07:38 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327306073 news.xs4all.nl 6877 [2001:888:2000:d::a6]:52624 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19250 On 1/23/2012 12:22 AM, Massimo Di Pierro wrote: > 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: If you want to get 2 rather than 2.0 after uncommenting, then I believe you should use // and __floordiv__. In fact, you do not even need the future import. But if you mean for Number to be like a float rather than int, do as you are (with / and __truediv__). Terry Jan Reedy