[Tutor] function fails on recursion

Jonathan Soons jsoons at juilliard.edu
Fri Nov 14 17:57:31 EST 2003


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) but I'd like to know the truth.
Can anyone help?

def mklines(field) :
    if len(field) < 4 :
        return
    words = field.split()
    while len(words) > 1 :
        while (len(words[0]) < 60) and len(words) > 1 :
            words[0] = words[0] + " " + words[1]
            words.remove(words[1])
        PDF_continue_text(pdf, words[0])
        words.remove(words[0])
#        if PDF_get_value(pdf, "texty", 0) < INCH : # If text gets too low on the page
#            words = string.joinfields(words, " ")  # turn words back into a string
#            newpage(words)                         # now I can feed it to newpage(string)
    if len(words) == 1 :
        PDF_continue_text(pdf, " " + words[0])

def newpage(words) :
    PDF_end_page(pdf)
    PDF_begin_page(pdf, WIDTH, HEIGHT)
    PDF_setfont(pdf, font0, 14)
    PDF_set_text_pos(pdf, INCH, 704)
    PDF_show(pdf, last + ", " + first)
    PDF_set_text_pos(pdf, INCH, 690)
    mklines(words)
            
##################### THIS IS THE ESSAY ######################

    if len(fields[321]) > 4 :  

        essay = fields[321]

        from pdflib_py import *
        pdf = PDF_new()
        PDF_open_file(pdf, os.path.join(fullpath, thisguy, thisguy + "_essay.pdf"))
        font0 = PDF_findfont(pdf, "Courier-Bold", "host", 0)
        font1 = PDF_findfont(pdf, "Courier", "host", 0)
        PDF_begin_page(pdf, WIDTH, HEIGHT)
        PDF_setfont(pdf, font0, 14)
        PDF_set_text_pos(pdf, 40, 690)
        PDF_show(pdf, last + ", " + first)
        PDF_set_text_pos(pdf, WIDTH - 144, 690)
        PDF_show(pdf, "ESSAY")
        PDF_setfont(pdf, font1, 12)
        PDF_set_text_pos(pdf, 40, 670)
        mklines(essay)                 # This is my function
        PDF_end_page(pdf) 
        PDF_close(pdf)
        PDF_delete(pdf)




More information about the Tutor mailing list