From e6221a7f282e8a14b2e19db231535ea66d0c1184 Mon Sep 17 00:00:00 2001 From: Rolux Date: Sun, 6 Jul 2008 12:37:29 +0200 Subject: [PATCH] optimize --- oxlib/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oxlib/text.py b/oxlib/text.py index a3c746b..5b2ec6b 100644 --- a/oxlib/text.py +++ b/oxlib/text.py @@ -69,17 +69,17 @@ def wrapString(string, length=80, separator='\n', balance=False): >>> wrapString('All you can eat', 12, '\n', True) 'All you \ncan eat' ''' + words = string.split(' ') if balance: # balance lines: test if same number of lines # can be achieved with a shorter line length lines = wrapString(string, length, separator, False).split(separator) if len(lines) > 1: - while length > max(map(lambda x : len(x), string.split(' '))): + while length > max(map(lambda x : len(x), words)): length -= 1 if len(wrapString(string, length, separator, False).split(separator)) > len(lines): length += 1 break - words = string.split(' ') lines = [''] for word in words: if len(lines[len(lines) - 1] + word + ' ') <= length + 1: