[Tutor] RE: Newbie problem with TypeError

Jonathan Soons jsoons at juilliard.edu
Mon Nov 17 12:13:18 EST 2003


>I am completely baffled by this TypeError.
>The program is 617 lines so I am just showing the relevant part.
>Please help.

>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)

I just took Danny Yoo's advice and changed this to:

def mklines(field) :
    if len(field) < 4 :
        return
    words = field.split(" ")
    while len(words) > 1 :
        line = ""
        list(words)                   #definitely a list
        while (len(line) < 60) and len(words) > 1 :
            line = line + " " + words[0]
            if len(words) > 0 :
                del(words[0])
        PDF_continue_text(pdf, line)
        if PDF_get_value(pdf, "texty", 0) < INCH :
            txt = string.joinfields(words, " ")  #new variable???!!!
            newpage(txt)                         #since the old one got stuck as a tuple.
    if len(words) == 1 :                         #and couldn't be made into a string
        PDF_continue_text(pdf, " " + words[0])

No error now but I don't know why I can't reuse the 'words' variable and cast it to string.
I can live with that tho since it now runs.
Thanks

>Traceback (most recent call last):
>  File "./parseapps.py", line 174, in ?
>      mklines(essay)
>	    File "./parseapps.py", line 50, in mklines
>		    del(words[0])
>			TypeError: object doesn't support item deletion




More information about the Tutor mailing list