Newbie problem with lists

Nick Coghlan ncoghlan at email.com
Fri Feb 28 12:34:03 CET 2003


Jacob H wrote:
>     for word in wordlist:
> 	
> 	wordlen = len(word)
> 
> 	if (wordlen + charcount + 1) > colwidth:
>             lines.append(text)
> 	    text = word + ' '
> 	    charcount = wordlen + 1
> 	else:
> 	    text = text + word + ' '
> 	    charcount = charcount + (wordlen + 1)

Try adding:
   lines.append(text)

between the two for loops - you currently seem to be missing the last line of text.

If your test string was < 116 characters, this would explain your problem.

Of course, if you have the option of playing with Python 2.3 then the program 
looks like:
=======
from textwrap import wrap

def render_text(text):
   lines = wrap(text, 58)
   for line in lines:
     # Do whatever it was you were doing in here
=======

Cheers,
Nick.


-- 
Nick Coghlan           |              Brisbane, Australia
ICQ#: 68854767         |        ncoghlan AT email DOT com
Mobile: 0409 573 268   |  http://oneofthesedays.not.there
"Let go your prejudices,
               lest they limit your thoughts and actions."





More information about the Python-list mailing list