argparse question

Larry Hudson orgnut at yahoo.com
Sun Feb 23 06:58:28 CET 2014


On 02/22/2014 03:58 AM, Peter Otten wrote:
> Larry Hudson wrote:
>
>> I have been reading the argparse section of the 3.3 docs, and running all
>> the example code.
>>
>> But in section 16.4.2.6. for the formatter_class, the second example in
>> that section illustrating RawDescriptionHelpFormatter, the example code
>> is:
>>
>> parser = argparse.ArgumentParser(
>>       prog='PROG',
>>       formatter_class=argparse.RawDescriptionHelpFormatter,
>>       description=textwrap.dedent('''\
>>           Please do not mess up this text!
>>           --------------------------------
>>               I have indented it
>>               exactly the way
>>               I want it
>>           '''))
>> parser.print_help()
>>
>> But trying to run this gives a NameError on the "description=" line,
>> saying textwrap is not
>> defined.  If I delete the "textwrap.dedent" (with or without also deleting
>> the extra parentheses) it will then run, but without the un-indenting it
>> is trying to illustrate.
>>
>> What is the proper way to enable the dedent() method here?
>
> textwrap is a module like argparse, and the example doesn't show
>
> import argparse
>
> either. Insert
>
> import textwrap
>
> at the beginning of your module and the code should run without error.
>

Thanx.
Guess I shoulda searched for textwrap or dedent in the docs.   :-)

      -=- Larry -=-





More information about the Python-list mailing list