小虾米12 发表于 2018-6-12 14:48:19

类覆盖出错!

class Nstr(str):
    def __Ishift__(self,other):
      return self + self[:other]
    def __rshift__(self,other):
      return self[-other:] + self[:-other]


'''
-----------------------python3.6-----------------
>>> a.__rshift__(3)
'om!I love FishC.c'
>>> a << 3
Traceback (most recent call last):
File "<pyshell#63>", line 1, in <module>
    a << 3
TypeError: unsupported operand type(s) for <<: 'Nstr' and 'int'

错在哪了?
---------------------------------------------------------
   
'''   

BngThea 发表于 2018-6-12 14:52:19

lshift 不是 Ishift

小虾米12 发表于 2018-6-12 15:01:32

BngThea 发表于 2018-6-12 14:52
lshift 不是 Ishift

嗯嗯,谢谢{:5_91:}
页: [1]
查看完整版本: 类覆盖出错!