Jak używać przeciążania metody w Pythonie?
Usiłuję zaimplementować przeciążanie metody w Pythonie:
<code>class A: def stackoverflow(self): print 'first method' def stackoverflow(self, i): print 'second method', i ob=A() ob.stackoverflow(2) </code>
ale wyjście jestsecond method 2
; podobnie:
<code>class A: def stackoverflow(self): print 'first method' def stackoverflow(self, i): print 'second method', i ob=A() ob.stackoverflow() </code>
daje
<code>Traceback (most recent call last): File "my.py", line 9, in <module> ob.stackoverflow() TypeError: stackoverflow() takes exactly 2 arguments (1 given) </code>
Jak to zrobić?