2009-09-01 20 views
3

我不知道這是在3.1中的錯誤,但如果我沒記錯的「內聯」師-3K版本前的工作是這樣的:的Python 3.1直列部門越權

Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> class A: 
...  def __init__(self, x): 
...    self.x = x 
...  def __idiv__(self, y): 
...    self.x /= y 
... 
>>> a = A(5) 
>>> a /= 2 

然而,給出3.1我這個:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: unsupported operand type(s) for /=: 'A' and 'int' 

...或者我錯過了什麼?

回答

6

Gaaah!發現__floordiv____truediv__。抱歉!

如果您想告訴我爲什麼2to3不能將__idiv__轉換爲__truediv__,請使用__floordiv__(self, y): self.__truediv__(y),請繼續!

+2

您可能想要提交一份關於該報告的錯誤報告。 – 2009-09-02 08:13:19

+0

我剛剛提交了。好主意 - 謝謝! – 2009-09-03 08:28:21