Title: optparse: formatting of help text/descriptions
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 2.7
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: LambertDW, akuchling, andybuckley, eric.araujo
Priority: normal Keywords:

Created on 2008-11-14 00:37 by akuchling, last changed 2012-11-04 00:37 by akuchling. This issue is now closed.

Messages (7)
msg75846 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2008-11-14 00:37
(Copied from an anonymous submission 
in the Optik bug tracker.)

There have been some recent discussions on comp.lang.python about the
optparse/optik module, and Steve Bethard suggested you might be interested
in some of the work done there. I don't know if you'd find any of this
helpful for inclusion in Optik/optparse, but Steve says it's come up on
your mailing list too.

The problem at hand involves formatting help-strings so that they respect
newlines. Simply passing formatted help-strings off to the textwrap.*
methods mungs the newlines and loses them.

The original thread:

My solution:

Dan then asked about it, and took my solution and ran with it:

Feel free to do with it as you like.
msg82754 - (view) Author: Andy Buckley (andybuckley) Date: 2009-02-26 13:55
FWIW, I would like to see an option on textwrap to preserve newlines for
purposes other than optparse formatting. optparse would then just be
able to pass that as a flag when building the text wrapper object.
Should I open a separate issue targeted at textwrap?
msg82762 - (view) Author: David W. Lambert (LambertDW) Date: 2009-02-26 14:46
I'd like textwrap option to preserve new lines.  Actual case:

I have a code that produces cryptograms meant to be printed and solved 
with paper and pencil.  Standard format for cryptogram inserts space 
character between each character of the original text, doubling the line 
length.  textwrap is handy to fit the cryptogram back to paper width.

Problem: When text to "cryptogramize" is a limerick original line breaks 
should be preserved.

P A Y C Y   H J K   J   K Q L Z   B J U R   G C V F   P C Y I P ,   H A 

 K V O N A P   I Y H   H J R K   P V   U Y U Y I P .   A Y C   P R E ' Y 

 L A V L Z   G O B B   V G   E V V   G C V F   J   N O B B .   K A Y 

 U Q Y U   B J K P   I Q N A P ;   K A Y   H J K   K E Y I P . 

 J I V I R F V O K

import string
import random
import textwrap

def Shuffle(L):
    return L

def create_cryptogram(quote):
        (disregards cryptogram rule that a letter can't stand for 
	doctest omitted
    # wish: wrap line-by-line to preserve original line breaks
    wrapped_quote = textwrap.fill(text=quote,width=38).upper()
    d = {c:c for c in string.printable}
    d['\n'] = '\n'*2
    UC = string.ascii_uppercase
    return ' '.join(d[c] for c in wrapped_quote)
msg82772 - (view) Author: David W. Lambert (LambertDW) Date: 2009-02-26 19:20
granted, this isn't terribly difficult:

'\n'.join(textwrap.fill(line) for line in text.split('\n'))
msg174722 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-11-04 00:35
optparse is not being developed anymore.
msg174723 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-11-04 00:36
amk: could you say if this applies to argparse?
msg174724 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2012-11-04 00:37
I have no idea.
Date User Action Args
2012-11-04 00:37:26akuchlingsetmessages: + msg174724
2012-11-04 00:36:09eric.araujosetmessages: + msg174723
2012-11-04 00:35:16eric.araujosetstatus: open -> closed

nosy: + eric.araujo
messages: + msg174722

resolution: rejected
stage: resolved
2009-02-26 19:20:12LambertDWsetmessages: + msg82772
2009-02-26 14:46:08LambertDWsetnosy: + LambertDW
messages: + msg82762
2009-02-26 13:55:03andybuckleysetnosy: + andybuckley
messages: + msg82754
2008-11-14 00:37:44akuchlingcreate