text wrapping help
attn.steven.kuo at gmail.com
attn.steven.kuo at gmail.com
Wed Feb 28 20:27:57 EST 2007
More information about the Python-list mailing list
Wed Feb 28 20:27:57 EST 2007
- Previous message (by thread): text wrapping help
- Next message (by thread): text wrapping help
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Feb 28, 4:06 pm, "Ryan K" <ryankas... at gmail.com> wrote: > I'm trying to text wrap a string but not using the textwrap module. I > have 24x9 "matrix" and the string needs to be text wrapped according > to those dimensions. Is there a known algorithm for this? Maybe some > kind of regular expression? I'm having difficulty programming the > algorithm. Try: import re sample_text = """Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet.""" # assume 24 is sufficiently wide: lines = map(lambda x: x.rstrip(), re.findall(r'.{1,24}(?:(?<=\S)\s|$)', sample_text.replace("\n", " "))) print "\n".join(lines) -- Hope this helps, Steven
- Previous message (by thread): text wrapping help
- Next message (by thread): text wrapping help
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list