I'm just beginning to learn python. I wrote an example script to test OOP in python, but something very odd has happened. When I call a class method, Python is calling the function with one more parameter than given.
Here is the code:
1. class Bar:
2. num1,num2 = 0,0
3. def __init__(num1,num2):
4. num1,num2 = num1,num2
5. def foo():
6. if num1 > num2:
7. print num1,'is greater than ',num2,'!'
8. elif num1 is num2:
9. print num1,' is equal to ',num2,'!'
10. else:
11. print num1,' is less than ',num2,'!'
12. a,b = 42,84
13. t = Bar(a,b)
14. t.foo
15.
16. t.num1 = t.num1^t.num2
17. t.num2 = t.num2^t.num1
18. t.num1 = t.num1^t.num2
19.
20. t.foo
And the error message I get:
python test.py
Traceback (most recent call last):
File "test.py", line 13, in
t = Bar(a,b)
TypeError: __init__() takes exactly 2 arguments (3 given)
Can anyone help?
Thanks in advance