- 论坛徽章:
- 0
|
- class first(object):
- def __init__(self,abc):
- self.abc=abc
- def gogogo(self,arg=[0,0,0,0,0,0,0,21,0,0,0,0,0]):
- for x in arg:
- if x == 0:
- continue
- strx=str(x)
- return strx
- class second(first):
- def gogogo(self):
- first.gogogo([0,0,0,0,0,0,0,57,0,0,0,0,0])
- a=second('abc')
- a.gogogo()
复制代码 执行报错
Traceback (most recent call last):
File "test.py", line 22, in <module>
a.gogogo()
File "test.py", line 16, in gogogo
first.gogogo([0,0,0,0,0,0,0,21,0,0,0,0,0])
TypeError: unbound method gogogo() must be called with first instance as first argument (got list instance instead)
我就是想重写一下父类的一个方法,但是我想省略后面一些过程,就是想偷懒一下。但是我这个思路显然有问题了,怎么最简化的重写父类除了init方法之外的方法呢? |
|