Wednesday, 15 February 2012

python - How to string format OptionParser() help message? -



python - How to string format OptionParser() help message? -

how string format optionparser() help message? seems ignore new line character? please see below code.

parser = optionparser() parser.add_option("--s", dest="s", type="string", help="first line \n sec line")

intention:

current output: .... first line \n sec line expected output: .... first line sec line

might suggest argparse?

i'm not sure if supported in optionparser, suggest using triple quote i.e:

parser = optionparser() parser.add_option('--s', dest='s' type='string' help=''' triple quotes can straight set in including line spaces. \n appear string rather newline.''')

argparse example:

import argparse parser = argparse.argumentparser() parser.add_argument('--s', help='''first line sec line''') args = parser.parse_args() print args.s

python linux terminal optparse optionparser

No comments:

Post a Comment