[Tutor] Help in debugging some Python code.
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Wed, 10 Jul 2002 12:05:58 -0700 (PDT)
> Traceback (most recent call last):
> File "test.py", line 12, in ?
> a=r.req()
> File "/usr/local/lib/python2.2/site-packages/DNS/Base.py", line 148, in
> req
> m.addQuestion(qname, qtype, DNS.Class.IN)
> File "/usr/local/lib/python2.2/site-packages/DNS/Lib.py", line 427, in
> addQuestion
> self.addname(qname)
> File "/usr/local/lib/python2.2/site-packages/DNS/Lib.py", line 105, in
> addname
> index.append(keys[j], offset + len(buf))
> TypeError: append() takes exactly one argument (2 given)
>
> Now I suspect that this utility was written for a previous version of
> Python, I'm using version 2.2 as you can see. I also suspect that the
> reported error is not the root of the problem but being inexperienced I
> don't know where to start looking for a solution. Any suggestions.
Hi Trevor,
My initial guess iwould be to change:
index.append(keys[j], offset + len(buf)) ## Buggy
to:
index.append((keys[j],
offset + len(buf))) ## Better
The append() method was changed between an old release of Python and the
more recent versions: the old version implicitely inserted a tuple
collection if we gave append() more arguments, but this seemed somewhat
magical and was seen as a language defect for a while.
The recent version of Python requires us to explictely say that we're
inserting that tuple, which is what that extra set of parentheses does.
Hope this helps!