def wrap_onspace(self, text, width): return reduce(lambda line, word, width=width: '%s%s%s' % ( line, ' ' if len(line.rsplit('\n')[-1]+word.split('\n')[0])>=width else '\n', word), text.split(' '))