[Tutor] function fails on recursion

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Nov 14 18:13:53 EST 2003



On Fri, 14 Nov 2003, Jonathan Soons wrote:

> I would really like to uncomment the commented lines. This program runs
> well as is and produces one good page but when it iterates (or
> recurses?) to produce page 2, etc. it fails with the message:
>
> Traceback (most recent call last):
>   File "./parseapps.py", line 171, in ?
>   mklines(essay)
>   File "./parseapps.py", line 46, in mklines
>   words[0] = words[0] + " " + words[1]
>   TypeError: object doesn't support item assignment
>
> I suspect 'words' has been somehow turned into a tuple. (It started out
> as a string)

Hi Jonathan,

Yes.  The lines:

        if PDF_get_value(pdf, "texty", 0) < INCH :
           words = string.joinfields(words, " ")
           newpage(words)

turns words from a list of strings into a single string, so it's a type
problem.  Instead of reassigning the result of joinfields() back into
'words', you may really want to use a different variable:

        if PDF_get_value(pdf, "texty", 0) < INCH :
           text = string.joinfields(words, " ")
           newpage(text)

This should prevent the TypeError (although the program might not be
correct quite yet... *grin*)

Hope this helps!




More information about the Tutor mailing list