|
From: <bc...@wo...> - 2001-02-13 09:58:40
|
[Brian Zhou]
>If I write:
>
>def init(self):
> # do something
> pass
>
>I got: TypeError: init() too many arguments; expected 1 got 2
>
>If I write:
>
>def init(self, config):
> javax.servlet.http.HttpServlet.init(self, config) # line 14, want
>to do super.init(config) here
> # do something
> pass
>
>I got:
>line 14, in init
>TypeError: init() not enough arguments; expected 2 got 1
>
>Am I missing anything?
In java, it is two different methods, but in jython the two methods is
merged into one. In a normal run this method will be called twice, first
with a config param and second (from within GenericServlet.init) without
any parameters.
So the jython method must be prepared to handle both situations:
def init(self, config=None):
if config:
HttpServlet.init(self, config)
pass
Obviously jython is completely defeating the purpose of the
parameter-less init() method:
"""
void init()
A convenience method which can be overridden so that there's no need
to call super.init(config).
"""
In jython, we are forced to deal with both init() methods *and* we have
to call super.init() as well.
regards,
finn
|