subclassing a module: misleading(?) error message

Huayang Xia huayang.xia at gmail.com
Thu Jan 4 22:42:42 CET 2007


So you know you are subclassing a module.

There is an answer @
http://www.velocityreviews.com/forums/showpost.php?p=1819038&postcount=2

On Jan 4, 3:49 pm, "Erik Johnson" <ej at somewhere.com> wrote:
> 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:
>
> > cat Super.pyclass Super(object):
>     def __init__(self):
>         self._class = 'Super'
>     def hello(self):
>         print "%s says 'Hello'" % self._class
>
> > cat Sub.pyimport Super
>
> class Sub(Super):
>     def __init__(self):
>         self._class = 'Sub'
>
> > pythonPython 2.3.4 (#1, Feb  7 2005, 15:50:45)
> [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> from Super import Super
> >>> from Sub import SubTraceback (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




More information about the Python-list mailing list