Trying To Subclass But Getting Object.__init__() Takes No Parameters
I'm trying to subclass web.form.Form from the webpy framework to change the behavior (it renders from in a table). I tried doing it in this way: class SyssecForm(web.form.Form):
Solution 1:
Just remove your __init__
method altogether, since you aren't really doing anything there, anyway.
Solution 2:
The message tells you all you need to know. The super-class is object and its constructor takes no parameters. So don't pass it the parameters for your constructor since it doesn't know what to do with them.
Call it like this:
super(SyssecForm, self).__init__()
Solution 3:
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 inself.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>"returnout
form = SyssecForm(web.form.Textbox("test"))
print form.render()
Your problem is because you might have outdated web.py, since web.form.Form inherits from object
now: https://github.com/webpy/webpy/commit/766709cbcae1369126a52aee4bc3bf145b5d77a8
Super only works for new-style classes. You have to add object
in class delcaration like this: class SyssecForm(web.form.Form, object):
or you have to update web.py.
Post a Comment for "Trying To Subclass But Getting Object.__init__() Takes No Parameters"