E
Erik Johnson
I ran into a problem I didn't understand at first. I got part of it figured
out. Let me first demonstrate the original problem:
class Super(object):
def __init__(self):
self._class = 'Super'
def hello(self):
print "%s says 'Hello'" % self._class
import Super
class Sub(Super):
def __init__(self):
self._class = 'Sub'
[GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "Sub.py", line 4, in ?
class Sub(Super):
TypeError: function takes at most 2 arguments (3 given)
My question is NOT "What's wrong here?"
(The answer to that is that the import in Sub.py should be: from Super
import Super
i.e., I tried to use the module itself where I meant to subclass the class
defined in that module).
My questions are:
Why does python complain about a function here? (it's a class definition
statement, right?)
Is there really a function being called here?
If so:
What function was called?
What two arguments is it expecting?
What three were given?
Thanks,
-ej
out. Let me first demonstrate the original problem:
cat Super.py
class Super(object):
def __init__(self):
self._class = 'Super'
def hello(self):
print "%s says 'Hello'" % self._class
cat Sub.py
import Super
class Sub(Super):
def __init__(self):
self._class = 'Sub'
Python 2.3.4 (#1, Feb 7 2005, 15:50:45)python
[GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "Sub.py", line 4, in ?
class Sub(Super):
TypeError: function takes at most 2 arguments (3 given)
My question is NOT "What's wrong here?"
(The answer to that is that the import in Sub.py should be: from Super
import Super
i.e., I tried to use the module itself where I meant to subclass the class
defined in that module).
My questions are:
Why does python complain about a function here? (it's a class definition
statement, right?)
Is there really a function being called here?
If so:
What function was called?
What two arguments is it expecting?
What three were given?
Thanks,
-ej