Attempting to subclass but getting .__ init __ () object takes no parameters

I am trying to subclass web.form.Form from a webpy framework to change the behavior (it displays from a table). I tried to do it as follows:

class SyssecForm(web.form.Form):

            def __init__(self, *inputs, **kw): 
                super(SyssecForm, self).__init__(*inputs, **kw)

            def render(self):
                out='<div id="form"> '
                for i in self.inputs:
                    html = utils.safeunicode(i.pre) + i.render() + self.rendernote(i.note) + utils.safeunicode(i.post)
                    out +=  "%s"%(html)  
                    out +=  '"<div id="%s"> %s %s</div>'% (i.id, net.websafe(i.description), html)
                out+= "</div>"
                return out

Now I get this error object.__init__() takes no parameters:

error traceback

+3
source share
3 answers

This works for me (web.py 0.37):

import web

class SyssecForm(web.form.Form):

    def __init__(self, *inputs, **kw): 
        super(SyssecForm, self).__init__(*inputs, **kw)

    def render(self):
        out='<div id="form"> '
        for i in self.inputs:
            html = web.utils.safeunicode(i.pre) + i.render() + self.rendernote(i.note) + web.utils.safeunicode(i.post)
            out +=  "%s"%(html)  
            out +=  '"<div id="%s"> %s %s</div>'% (i.id, web.net.websafe(i.description), html)
        out+= "</div>"
        return out

form = SyssecForm(web.form.Textbox("test"))
print form.render()

Your problem is that you may have an outdated web.py since web.form.Form now inherits from object: https://github.com/webpy/webpy/commit/766709cbcae1369126a52aee4bc3bf145b5d77a8

. object delcaration : class SyssecForm(web.form.Form, object): web.py.

+1

__init__ , .

+3

A message tells you everything you need to know. A superclass is an object, and its constructor does not accept any parameters. Therefore, do not pass parameters for your constructor to it, since it does not know what to do with them.

Name it as follows:

super(SyssecForm, self).__init__()
+2
source

All Articles