A 'Box' Function

Kent Johnson kent at kentsjohnson.com
Tue Apr 18 12:19:21 EDT 2006


mikelaskey at gmail.com wrote:
> Hey guys.
> 
> I should warn you, first off, that I'm relatively new to Python.
> Basically, what I'm trying to do is create a word-wrapping function
> with the added complication that it add a character at the beginning
> and end of each line, so that it encloses the text in a sort of 'box':
> 
> ----------------
> | Like this |
> ----------------
> 
> The word-wrapping function I'm working with is similar to the one given
> here:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/148061
> 
> Does anyone have any ideas on how it could be modified?  Am I
> approaching it the right way?  Thanks a bunch!

Rather than rewriting wrap(), I would suggest wrapping it with a new 
function, wrap_box(), that adds the header, line endings and trailer to 
the lines returned from wrap().

Kent



More information about the Python-list mailing list